It's O(n), also check out: http://wiki.python.org/moin/TimeComplexity

This page documents the time-complexity (aka "Big O" or "Big Oh") of various operations in current CPython. Other Python implementations (or older or still-under development versions of CPython) may have slightly different performance characteristics. However, it is generally safe to assume that they are not slower by more than a factor of O(log n)...

Answer from Zach Kelling on Stack Overflow
๐ŸŒ
Analytics Vidhya
analyticsvidhya.com โ€บ home โ€บ how can i manipulate python list elements using indexing?
How can I Manipulate Python List Elements Using Indexing?
January 22, 2024 - Direct indexing has a time complexity of O(1), while using the index() method for searching has a time complexity of O(n).
Discussions

python - How can I find the index for a given item in a list? - Stack Overflow
Given a list ["foo", "bar", "baz"] and an item in the list "bar", how do I get its index 1? More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - what is the time complexity of list.index(obj) method? - Stack Overflow
This page documents the time-complexity (aka "Big O" or "Big Oh") of various operations in current CPython. Other Python implementations (or older or still-under development versions of CPython) may have slightly different performance characteristics. However, it is generally safe to assume that they are not slower by more than a factor of O(log n).. ... Find ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - What is the time complexity to get the last index for an array? - Stack Overflow
for the given array it takes O(1) ... index or it knows that the array ends at index 3 by default ? In other words how is array[-1] is implemented in python? ... That's not an array, it's a list. ... Accessing any array element is in constant time, since it is a known by memory ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - What is (list.index() inside a for loop) complexity - Stack Overflow
For each number in (first list): Second list.index(number) -> variable Print (index of number in first list) and (variable) More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Medium
medium.com โ€บ @ivanmarkeyev โ€บ understanding-python-list-operations-a-big-o-complexity-guide-49be9c00afb4
Understanding Python List Operations: A Big O Complexity Guide | by Ivan Markeev | Medium
June 4, 2023 - Under the hood, lists use an underlying array structure to store their elements. This enables direct access to any element by index, resulting in O(1) complexity. Regardless of the size of the list, accessing an element takes the same amount of time.
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ python list index() โ€“ a simple illustrated guide
Python List index() - A Simple Illustrated Guide - Be on the Right Side of Change
June 19, 2021 - The index() method has linear runtime complexity in the number of list elements. For n elements, the runtime complexity is O(n) because in the worst-case you need to iterate over each element in the list to find that the element does not appear ...
Top answer
1 of 16
6115
>>> ["foo", "bar", "baz"].index("bar")
1

See the documentation for the built-in .index() method of the list:

list.index(x[, start[, end]])

Return zero-based index in the list of the first item whose value is equal to x. Raises a ValueError if there is no such item.

The optional arguments start and end are interpreted as in the slice notation and are used to limit the search to a particular subsequence of the list. The returned index is computed relative to the beginning of the full sequence rather than the start argument.

Caveats

Linear time-complexity in list length

An index call checks every element of the list in order, until it finds a match. If the list is long, and if there is no guarantee that the value will be near the beginning, this can slow down the code.

This problem can only be completely avoided by using a different data structure. However, if the element is known to be within a certain part of the list, the start and end parameters can be used to narrow the search.

For example:

>>> import timeit
>>> timeit.timeit('l.index(999_999)', setup='l = list(range(0, 1_000_000))', number=1000)
9.356267921015387
>>> timeit.timeit('l.index(999_999, 999_990, 1_000_000)', setup='l = list(range(0, 1_000_000))', number=1000)
0.0004404920036904514

The second call is orders of magnitude faster, because it only has to search through 10 elements, rather than all 1 million.

Only the index of the first match is returned

A call to index searches through the list in order until it finds a match, and stops there. If there could be more than one occurrence of the value, and all indices are needed, index cannot solve the problem:

>>> [1, 1].index(1) # the `1` index is not found.
0

Instead, use a list comprehension or generator expression to do the search, with enumerate to get indices:

>>> # A list comprehension gives a list of indices directly:
>>> [i for i, e in enumerate([1, 2, 1]) if e == 1]
[0, 2]
>>> # A generator comprehension gives us an iterable object...
>>> g = (i for i, e in enumerate([1, 2, 1]) if e == 1)
>>> # which can be used in a `for` loop, or manually iterated with `next`:
>>> next(g)
0
>>> next(g)
2

The list comprehension and generator expression techniques still work if there is only one match, and are more generalizable.

Raises an exception if there is no match

As noted in the documentation above, using .index will raise an exception if the searched-for value is not in the list:

>>> [1, 1].index(2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: 2 is not in list

If this is a concern, either explicitly check first using item in my_list, or handle the exception with try/except as appropriate.

The explicit check is simple and readable, but it must iterate the list a second time. See What is the EAFP principle in Python? for more guidance on this choice.

2 of 16
725

The majority of answers explain how to find a single index, but their methods do not return multiple indexes if the item is in the list multiple times. Use enumerate():

for i, j in enumerate(['foo', 'bar', 'baz']):
    if j == 'bar':
        print(i)

The index() function only returns the first occurrence, while enumerate() returns all occurrences.

As a list comprehension:

[i for i, j in enumerate(['foo', 'bar', 'baz']) if j == 'bar']

Here's also another small solution with itertools.count() (which is pretty much the same approach as enumerate):

from itertools import izip as zip, count # izip for maximum efficiency
[i for i, j in zip(count(), ['foo', 'bar', 'baz']) if j == 'bar']

This is more efficient for larger lists than using enumerate():

$ python -m timeit -s "from itertools import izip as zip, count" "[i for i, j in zip(count(), ['foo', 'bar', 'baz']*500) if j == 'bar']"
10000 loops, best of 3: 174 usec per loop
$ python -m timeit "[i for i, j in enumerate(['foo', 'bar', 'baz']*500) if j == 'bar']"
10000 loops, best of 3: 196 usec per loop
๐ŸŒ
Flexiple
flexiple.com โ€บ python โ€บ python-program-accessing-index-value-list
Python Program To Accessing Index And Value In A List - Flexiple
March 18, 2024 - This method is highly effective for complex data structures and is widely used in data manipulation and analysis tasks in Python. Time Complexity: O(n) Space Complexity: O(n), as we are creating a numpy array of size n.
๐ŸŒ
Apps Developer Blog
appsdeveloperblog.com โ€บ home โ€บ python โ€บ python list index()
Python List index() - Apps Developer Blog
January 27, 2023 - The index function finds the match by checking every element of the list until the match is found. Thus, for a smaller list, this is a good choice. But if you are dealing with huge lists and you are not sure whether the match will be found or not, then this function is not. This will increase the time cost of your code. So the longer the list, the more amount of time it will take. To avoid the time complexity, you can narrow down the search by giving the start and end parameters.
Find elsewhere
๐ŸŒ
Quora
quora.com โ€บ How-do-Python-lists-maintain-constant-time-complexity-for-indexing-if-their-elements-can-be-of-more-than-one-type
How do Python lists maintain constant time complexity for indexing if their elements can be of more than one type? - Quora
Answer (1 of 4): in a C arrays where the data is held in contiguous memory, you are right that indexing couldnโ€™t be constant time in a heterogeneous container as you would have to sum the widths of all of the previous items before being able to fetch an item (or you would need to keep a separate ...
๐ŸŒ
AlgoCademy
algocademy.com โ€บ link
Time Complexity Guidelines in Python | AlgoCademy
The code is straightforward and leverages Python's ability to access list elements in constant time. The time complexity of the optimized solution is O(1) because accessing an element by its index in a list is a constant time operation.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-find-elements-of-a-list-by-indices
Python | Find elements of a list by indices - GeeksforGeeks
March 18, 2023 - # Python3 program to Find elements ... [10, 20, 30, 40, 50] lst2 = [0, 2, 4] print(findElements(lst1, lst2)) ... Time complexity: O(n), where n is the length of lst2 Auxiliary space: O(m), where m is the length of the returned ...
๐ŸŒ
Python
wiki.python.org โ€บ moin โ€บ TimeComplexity
TimeComplexity - Python Wiki
Note that there is a fast-path ... complexity, but it can significantly affect the constant factors: how quickly a typical program finishes. [1] = These operations rely on the "Amortized" part of "Amortized Worst Case". Individual actions may take surprisingly long, depending on the history of the container. [2] = Popping the intermediate element at index k from a list ...
๐ŸŒ
LearnPython.com
learnpython.com โ€บ blog โ€บ python-get-index-of-item-list
How to Get the Index of an Item in a List in Python | LearnPython.com
Another drawback of the index() method is that it has a linear time complexity in its length. If we have a list of 1 million items and the item we are searching for is the last one, then the search may take a very long time.
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python โ€บ lists โ€บ .index()
Python | Lists | .index() | Codecademy
June 11, 2025 - In the worst case, the .index() method has O(n) time complexity, as it may need to check every element. Consider using dictionaries or other data structures that offer faster lookup times for frequently repeated searches on large lists.
๐ŸŒ
Quora
quora.com โ€บ What-are-the-time-complexity-considerations-of-lists-in-Python
What are the time complexity considerations of lists in Python? - Quora
Answer: In a normal list on average: * Append : O(1) * Extend : O(k) - k is the length of the extension * Index : O(1) * Slice : O(k) * Sort : O(n log n) - n is the length of the list * Len : O(1) * Pop : O(1) - pop from end * Insert : O(n) - n is the length of the list * Del : O(n) - n...
๐ŸŒ
Analytics Vidhya
analyticsvidhya.com โ€บ home โ€บ python list index: a guide to finding and manipulating list elements
Python List Index: A Guide to Finding and Manipulating List Elements
January 23, 2024 - Different operations have different time complexities, and choosing the most efficient operation can significantly impact the performance of our code. For example, accessing an element by its index has a time complexity of O(1), as it directly ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ does pop(i) have a time complexity of o(n) or o(k)?
r/learnpython on Reddit: Does pop(i) have a Time Complexity of O(n) or O(k)?
July 1, 2020 - For example, as n grows, any fixed negative index value to list.pop() will be O(1), and any fixed non-negative value will be O(n). So 'k' captures the idea that the time-complexity is "parameterized" not by n, but some other variable. ... If you pop the last element it is O(1), if you pop the first element it is O(n). So yes, your understand seems correct. Big O Cheat Sheet: the time complexities of operations Python's data structures
๐ŸŒ
Keploy
keploy.io โ€บ home โ€บ community โ€บ find elements in a python list: 7 methods with code examples
Find Elements in a Python List: 7 Methods with Code Examples | Keploy Blog
April 4, 2026 - Searching with in or list.index() has a time complexity of O(n) in the worst case. For faster searches, consider using sets or dictionaries, which have average O(1) lookup time. ... Swapnoneel is a front-end developer and technical writer with ...