'How is the list.index() method implemented? [duplicate]

I'm interested in the time complexity of the .index() in python function I'm trying to find the implementation in the docs but nothing so far.



Solution 1:[1]

Most likely the complexity is O(n) as the code has to traverse the list from front to back until it finds the first occurrence of the desired item. It cannot make assumptions about whether the list is sorted or not.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 fpeterek