there is a very detailed table on python wiki which answers your question.

However, in your particular example you should use enumerate to get an index of an iterable within a loop. like so:

for i, item in enumerate(some_seq):
    bar(item, i)
Answer from SilentGhost on Stack Overflow
🌐
Python
wiki.python.org › moin › TimeComplexity
TimeComplexity - Python Wiki
(Well, a list of arrays rather than objects, for greater efficiency.) Both ends are accessible, but even looking at the middle is slow, and adding to or removing from the middle is slower still. See dict -- the implementation is intentionally very similar. As seen in the source code the complexities for set difference s-t or s.difference(t) (set_difference()) and in-place set difference s.difference_update(t) (set_difference_update_internal()) are different!
Discussions

What is the time complexity of the “in” operation
This moved much faster. Because it does fewer tests - if you're checking for membership in a list, you can stop as soon as you find the element. If you're comparing every element of the list to a value, as the first example does, then you check every element of the list. Doing less is always faster. More on reddit.com
🌐 r/learnpython
10
2
September 1, 2021
algorithm - Time Complexity of List creation in Python - Stack Overflow
Would the time complexity of these operations be O(N)? Because, you would need to iterate through all of the items up to N and append it to the list. Append is O(1). Therefore, it is N*O(1) = O(N). Thoughts? Thanks. ... Thanks everyone. Those threads suggest it is O(N), which is what I speculate. But they don't explain why. Can anyone find concrete proof why creating a list of size N will be O(N) in python... More on stackoverflow.com
🌐 stackoverflow.com
Complexity of *in* operator in Python - Stack Overflow
Even if it was something in particular, Python is dynamic, so state it explicitly in a case like this. ... L means list? My libtelepathy.so is probably outdated. ... The complexity of in depends entirely on what L is. e in L will become L.__contains__(e). See this time complexity document for ... More on stackoverflow.com
🌐 stackoverflow.com
Time Complexity of Python list comprehension then list[i] = value vs. list = [] then list.append(value)
In terms of Big O the algorithms are equivalent to each other as they both have linear growth. As you say, the list comprehension in the first example is O(n) so the function is O(2n), but in algorithmic analysis that is considered equivalent to O(n). In practical terms the second approach is better as it only requires one iteration over the input array. More on reddit.com
🌐 r/learnprogramming
5
2
September 26, 2021
🌐
GeeksforGeeks
geeksforgeeks.org › python › complexity-cheat-sheet-for-python-operations
Complexity Cheat Sheet for Python Operations - GeeksforGeeks
July 12, 2025 - This cheat sheet is designed to help developers understand the average and worst-case complexities of common operations for these data structures that help them write optimized and efficient code in Python. Python's list is an ordered, mutable sequence, often implemented as a dynamic array. Below are the time complexities for common list operations:
🌐
Quora
quora.com › What-are-the-time-complexity-considerations-of-lists-in-Python
What are the time complexity considerations of lists in Python? - Quora
Most systems abstract those, like hashing time of a string. It is not constant. It is linear with strings length and then some. So… do not use those. Find something that works, that is actually fast - if that is your requirement. ... Zoho One gives you 50+ business apps in a single platform. ... Python lists are dynamic arrays (CPython implementation). Time complexity for common operations follows predictable amortized and worst-case patterns.
🌐
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 - Appending one list to another in Python takes time proportional · to the length of the list being appended (k). The elements of the second list need to be copied to the first list, resulting in O(k) complexity.
🌐
Python Morsels
pythonmorsels.com › time-complexities
Python Big O: the time complexities of different data structures in Python - Python Morsels
April 16, 2024 - For inexpensive operations involving the least-recently added item (the beginning of a list), we'd need a queue-like structure. That's what Python's collections.deque data structure is for. >>> from collections import deque >>> queue = deque([2, 1, 3, 4]) Here are the time complexities of common deque operations:
🌐
LabEx
labex.io › tutorials › python-what-is-the-time-complexity-of-list-append-and-remove-operations-in-python-397728
What is the time complexity of list append and remove operations in Python | LabEx
The time complexity of an algorithm is typically expressed using Big O notation, which provides an upper bound on the growth rate of the algorithm's running time as the input size increases.
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › what is the time complexity of the “in” operation
r/learnpython on Reddit: What is the time complexity of the “in” operation
September 1, 2021 -

I’m not the biggest python user. But I was looking at a friends code yesterday and they had something like:

For x in (list of 40000)

For y in (list of 2.7 million)

  If x = y 

     Append something 

This was obviously super slow so they changed it to something like:

For x in (list of 2.7 million)

If y in (list of 40000)

  Append something 

This moved much faster. I get the point of one for loop being faster than two, but what is that “in” exists function doing that makes it so much faster. I always thought that to check if something exists is O(n) which shouldn’t be faster. Also this was for ML purposes so they were likely using numpy stuff.

🌐
GeeksforGeeks
geeksforgeeks.org › python › time-complexity-of-a-list-to-set-conversion-in-python
Time Complexity of A List to Set Conversion in Python - GeeksforGeeks
July 23, 2025 - The time to convert small list to set : 0.0 The set is : {1, 2, 3, 4, 5} The time to convert large list to set : 0.21737 · The time complexity of list to set conversion is O(n) where n is the number of element in the list.
🌐
DEV Community
dev.to › williams-37 › understanding-time-complexity-in-python-functions-5ehi
Understanding Time Complexity in Python Functions - DEV Community
October 25, 2024 - ... Removing an element (by value) requires searching for the element first, which takes linear time. ... Python’s built-in sorting algorithm (Timsort) has a time complexity of O(n log n) in the average and worst cases.
🌐
Stack Overflow
stackoverflow.com › questions › 65261092 › time-complexity-of-list-creation-in-python
algorithm - Time Complexity of List creation in Python - Stack Overflow
Technically append is only O(1) amortised time, but that's good enough for the proof to work. ... It depends on how the list particularly was implemented. For example, if you already have a list that you pass as an argument, the upper bound ...
🌐
Quora
quora.com › What-is-the-time-complexity-of-the-Python-lists-count-function
What is the time complexity of the Python list's count() function? - Quora
In CPython (the main implementation of Python) the time complexity of the find() function is O((n-m)*m) where n is the size of the string in which you search, and m is the size of the string which you search.
🌐
DEV Community
dev.to › iihsan › time-complexity-analysis-of-python-methods-bigo-notations-for-list-tuple-set-and-dictionary-methods-47l9
Time Complexity Analysis of Python Methods: Big(O) Notations for List, Tuple, Set, and Dictionary Methods - DEV Community
January 15, 2024 - For example, list.append(). As the list reserves some memory, so until it is utilized, list.append() gives O(1). However, when the reserved memory is filled, and new memory is required, a new list is created with more space, copying all elements. While this operation is not always constant time, it happens infrequently. So, we refer to it as Amortized constant time. The IN Operator uses linear search with a time complexity of O(n). Thanks for reading! Feel free to like, comment, and share if you find this article valuable. You can check my other articles as well: Mastering Metaclasses in Python using real-life scenarios Use Asynchronous Programming in Python: Don’t Block Entire Thread
🌐
Medium
medium.com › @hamzaehsankhan › why-len-list-has-a-time-complexity-of-o-1-a-dive-into-cpython-cbed75c38b54
Why len(list) has a time-complexity of O(1)? — A dive into CPython | by Hamza Ehsan Khan | Medium
July 13, 2023 - This in-built function is not at the mercy of the size of the list. Whether your list contains 1 element or 1000, as per the default implementation of Python (CPython), the time-complexity is O(1).
🌐
Sololearn
sololearn.com › en › Discuss › 2409293 › time-complexity-of-listcount-in-python
Time complexity of list.count in Python | Sololearn: Learn to code for FREE!
... Bagon I've done some research in the CPython code and found that ob_size is no longer part of the PyListObject struct so it has to iterate over the list to count the elements. This means that at least CPython has O(n) for counting list elements.
🌐
Plain English
python.plainenglish.io › exploring-python-lists-understanding-methods-operations-and-time-complexity-66242073716a
“Exploring Python Lists: Understanding Methods, Operations, and Time Complexity” | by Ewho Ruth | Python in Plain English
December 5, 2024 - The time complexity for accessing an element in a list by index is O(1) Here are some common operations on lists in Python along with real-world examples and their time complexities:
🌐
YourBasic
yourbasic.org › algorithms › time-complexity-arrays
Time complexity of array/list operations [Java, Python] · YourBasic
The following Python list operations operate on a subset of the elements, but still have time complexity that depends on n = len(a). Note: a.append(x) takes constant amortized time, even though the worst-case time is linear.
🌐
Quora
quora.com › How-fast-are-list-operations-in-Python
How fast are list operations in Python? - Quora
Answer (1 of 3): I went ahead and analyzed the runtime-complexities of some common list operations. Disclaimer: I have confidence in these complexities, but use at your own risk, etc. I welcome corrections, and have some questions about the implementation (see the end of the post). http://svn....
🌐
ESS Institute
essinstitute.in › home › blog › introduction to time complexity in python
Introduction to Time complexity in Python | ESS Institute
June 3, 2023 - When we kook out\ for an element ... the time complexity of a hash table search is O(1) as opposed to O(n) for an array. When processing a lot of data, this improvement can help us save a lot of time. Additionally, it helps us stay clear of programming errors like nested loops and recursive functions, which can cause extremely slow execution. Arrays are a basic data structure that let us efficiently store and access components of the same type. Python implements arrays as lists, and the following ...