list

The Average Case assumes parameters generated uniformly at random.

Internally, a list is represented as an array; the largest costs come from growing beyond the current allocation size (because everything must move), or from inserting or deleting somewhere near the beginning (because everything after that must move). If you need to add/remove at both ends, consider using a collections.deque instead.

So inserting an element at given position will always have the time complexity of O(n) as both insert method and slicing has time complexity of O(n) and O(k). Only append which inserts at the end of list have O(1) time complexity. From Python Wiki

Lists:
                               Complexity
Operation     | Example      | Class         | Notes
--------------+--------------+---------------+-------------------------------
Index         | l[i]         | O(1)          |
Store         | l[i] = 0     | O(1)          |
Length        | len(l)       | O(1)          |
Append        | l.append(5)  | O(1)          |
Clear         | l.clear()    | O(1)          | similar to l = []

Slice         | l[a:b]       | O(b-a)        | l[1:5]:O(l)/l[:]:O(len(l)-0)=O(N)
Extend        | l.extend(...)| O(len(...))   | depends only on len of extension
Construction  | list(...)    | len(...)      | depends on lenghth of argument

check ==, !=  | l1 == l2     | O(N)          |
Insert        | l[a:b] = ... | O(N)          |
Delete        | del l[i]     | O(N)          | 
Remove        | l.remove(...)| O(N)          | 
Containment   | x in/not in l| O(N)          | searches list
Copy          | l.copy()     | O(N)          | Same as l[:] which is O(N)
Pop           | l.pop(...)   | O(N)          |
Pop           | l.pop()      | O(1)          | same as l.pop(-1), popping at end
Extreme value | min(l)/max(l)| O(N)          |
Reverse       | l.reverse()  | O(N)          |
Iteration     | for v in l:  | O(N)          |

Sort          | l.sort()     | O(N Log N)    | key/reverse doesn't change this
Multiply      | k*l          | O(k N)        | 5*l is O(N): len(l)*l is O(N**2)

From here

Answer from Tanveer Alam on Stack Overflow
Top answer
1 of 4
65

list

The Average Case assumes parameters generated uniformly at random.

Internally, a list is represented as an array; the largest costs come from growing beyond the current allocation size (because everything must move), or from inserting or deleting somewhere near the beginning (because everything after that must move). If you need to add/remove at both ends, consider using a collections.deque instead.

So inserting an element at given position will always have the time complexity of O(n) as both insert method and slicing has time complexity of O(n) and O(k). Only append which inserts at the end of list have O(1) time complexity. From Python Wiki

Lists:
                               Complexity
Operation     | Example      | Class         | Notes
--------------+--------------+---------------+-------------------------------
Index         | l[i]         | O(1)          |
Store         | l[i] = 0     | O(1)          |
Length        | len(l)       | O(1)          |
Append        | l.append(5)  | O(1)          |
Clear         | l.clear()    | O(1)          | similar to l = []

Slice         | l[a:b]       | O(b-a)        | l[1:5]:O(l)/l[:]:O(len(l)-0)=O(N)
Extend        | l.extend(...)| O(len(...))   | depends only on len of extension
Construction  | list(...)    | len(...)      | depends on lenghth of argument

check ==, !=  | l1 == l2     | O(N)          |
Insert        | l[a:b] = ... | O(N)          |
Delete        | del l[i]     | O(N)          | 
Remove        | l.remove(...)| O(N)          | 
Containment   | x in/not in l| O(N)          | searches list
Copy          | l.copy()     | O(N)          | Same as l[:] which is O(N)
Pop           | l.pop(...)   | O(N)          |
Pop           | l.pop()      | O(1)          | same as l.pop(-1), popping at end
Extreme value | min(l)/max(l)| O(N)          |
Reverse       | l.reverse()  | O(N)          |
Iteration     | for v in l:  | O(N)          |

Sort          | l.sort()     | O(N Log N)    | key/reverse doesn't change this
Multiply      | k*l          | O(k N)        | 5*l is O(N): len(l)*l is O(N**2)

From here

2 of 4
31

The Python language doesn't specify the implementation of such operations, so different implementations may have different behavior. For CPython, the complexity of list.insert is O(n), as shown on this useful wiki page. I'm not aware of any list-like structure giving O(1) performance for inserting at an arbitrary index. (A dict gives O(1) insert performance in the average case, but is not ordered and does not enforce a contiguous sequence of indices.) The blist library provides an optimized list type that has an O(log n) insert.

🌐
Reddit
reddit.com › r/learnpython › what is the time complexity (big o) for insertion of an element in the end of an array?
r/learnpython on Reddit: What is the Time complexity (Big O) for insertion of an element in the end of an Array?
January 3, 2021 -

Assume I have a code:

arr1=array("i", [1, 2, 3, 4, 5])

I just wanted to ask what would be the time complexity for inserting an element at the end of the array by using the code:

arr1.insert(5,6)

output: array('i', [1, 2, 3, 4, 5, 6])

Although, I found online that Big O is O(1) but I don't get it. Initially my array was of fixed sized(5) and if I need to add a new element, I am essentially copying the old array [1,2,3,4,5] and pasting it in a new memory location with an empty space at the end so that I could add [6] in the end. This is my understanding, if this is right how is O(1) correct? shouldn't it be more?

Edit: It's O(n)

Discussions

insert - Python list insertion run time complexity - Stack Overflow
I know that inserting to list is O(n) since the worst case is insert to index 0. Now my question is, what if we let A, B be lists such that len(A) = len(B) = N and we're trying to insert into A each More on stackoverflow.com
🌐 stackoverflow.com
What is Python's list.append() method WORST Time Complexity? It can't be O(1), right?
Personally, I thought that lists worked as double LinkedLists, so insert time was O(1) But if it works as a dynamic array, time complexity should be amortized time, ie, close to O(1) but not quite More on reddit.com
🌐 r/learnpython
11
3
October 26, 2022
python - Does insert at the end of a list have O(1) time complexity? - Stack Overflow
Worst time complexity for inserting ... of the list and i is the index at which you are inserting. So in case if you are inserting at the last index, that makes it O(1). Here is an article that might help you understand better : https://yourbasic.org/algorithms/time-complexity-arrays/. ... Save this answer. ... Show activity on this post. Regarding "equivalent in functionality", I'd say it is true since both of them will produce the exact same results for Python ... More on stackoverflow.com
🌐 stackoverflow.com
What is the Time complexity (Big O) for insertion of an element in the end of an Array?
Python lists and arrays preallocate extra memory so that you can append to them as O(1). In that sense they are not real arrays like we are taught. More on reddit.com
🌐 r/learnpython
9
1
January 3, 2021
🌐
Python
wiki.python.org › moin › TimeComplexity
TimeComplexity - Python Wiki
Internally, a list is represented as an array; the largest costs come from growing beyond the current allocation size (because everything must move), or from inserting or deleting somewhere near the beginning (because everything after that must move).
🌐
GeeksforGeeks
geeksforgeeks.org › python › time-complexity-for-adding-element-in-python-set-vs-list
Time Complexity for Adding Element in Python Set vs List - GeeksforGeeks
July 23, 2025 - When we add an element to a list using the append() method, Python directly adds the element to the end. This operation has O(1) amortized time complexity, as no hashing or duplicate checks are needed.
🌐
edSlash
edslash.com › home › python tutorials – learn with edslash › insert() method in list – python
insert() method in list - Python - edSlash
September 21, 2024 - When we call .insert() method with ... is negative then it will insert element at beginning of the list. You can also pass negative index to the insert method. The .insert() method takes O(n) time complexity where n is the number of elements....
🌐
TutorialKart
tutorialkart.com › python › python-list-insert
Insert element at given index in list in Python - TutorialKart
July 5, 2024 - The time complexity to insert an element at a given index is O(n). This means that the complexity increases linearly with the number of elements in the list. In this Python Tutorial, we have learned the syntax of list.insert() method and its ...
🌐
Medium
jimmy-shen.medium.com › the-complexity-of-insert-an-element-in-a-list-57de6a8b0ba
The complexity of insert an element in a list | by Jimmy (xiaoke) Shen | Medium
June 6, 2020 - Python’s list is not the data structure list, from the data structure’s perspective, it is more like a stack. class Solution: def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]: people.sort(key=lambda x:(x[0], -x[1])) res = [] while people: h, v = people.pop() res.insert(v, [h, v]) return res · I am still looking for an O(1) solution to insert the element into a specified spot.
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 73559822 › python-list-insertion-run-time-complexity
insert - Python list insertion run time complexity - Stack Overflow
I know that inserting to list is O(n) since the worst case is insert to index 0. Now my question is, what if we let A, B be lists such that len(A) = len(B) = N and we're trying to insert into A each
🌐
Bacancy Technology
bacancytechnology.com › qanda › python › pythons-list-append-method-has-01-time-complexity
Why Python’s list.append() Method Has O(1) Time Complexity
July 14, 2025 - Python lists are implemented as dynamic arrays. When you use the append() method, Python may sometimes resize the underlying array, but this resizing doesn’t happen every time. Appending to a list is considered amortized O(1) time complexity.
🌐
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...
🌐
Finxter
blog.finxter.com › home › learn python blog › python list insert() method
Python List insert() Method - Be on the Right Side of Change
June 19, 2021 - In the third part of the code, you plot everything using the Python matplotlib library. Here’s the resulting plot that compares the runtime of the two methods append() vs extend(). On the x axis, you can see the list size from 0 to 1,000,000 elements. On the y axis, you can see the runtime in seconds needed to execute the respective functions. The resulting plot shows that both methods are extremely fast for a few tens of thousands of elements. In fact, they are so fast that the time() function of the time module cannot capture the elapsed time.
🌐
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 - It’s important to note that these time complexities are average cases, and they may vary depending on factors such as the size of the list, the specific operation being performed, and the underlying implementation of the Python interpreter.
🌐
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
This is because the list.append() operation simply adds a new element to the end of the list, and the underlying implementation of the Python list data structure is designed to handle this operation efficiently. Here's an example code snippet to demonstrate the constant time complexity of the list.append() operation:
🌐
Tutorialspoint
tutorialspoint.com › python › list_insert.htm
Python List insert() Method
Once the insertion of an element ... using the indexing technique, the time complexity of this method is O(n) where n is the number of elements in the list....
🌐
Pdxdev
python.pdxdev.com › lists › how-fast-is-list.insert-python
Unveiling the Speed of `list.insert()` in Python
When you use list.insert(), Python has to shift all existing elements after the insertion point one position to the right to make room for the new item. This shifting operation is what contributes to the time complexity of list.insert() being O(n), where ’n’ is the number of elements in the list.
🌐
Python Morsels
pythonmorsels.com › time-complexities
Python Big O: the time complexities of different data structures in Python - Python Morsels
April 16, 2024 - Thanks to the power of hashing, ... the value of an item, and removing an item are all constant time operations (that's O(1) in big O)....
🌐
C# Corner
c-sharpcorner.com › home › technologies › python › python list insertions explained: from single elements to bulk and conditional regions
Python List Insertions Explained: From Single Elements to ...
September 29, 2025 - Core Python Tools for Insertion · Inserting a Single Element at a Specific Index · Inserting Multiple Elements at a Region · Inserting Based on Conditional Regions (Value-Based) Real-World Scenario: Time-Series Data Interpolation · Inserting into 2D Arrays (Matrices) Algorithmic Analysis: Time and Space Complexity · Common Pitfalls and How to Avoid Them · Complete Code Implementation & Test Cases · Conclusion · Appending to the end of a list (list.append()) is trivial.
🌐
Reddit
reddit.com › r/learnpython › what is python's list.append() method worst time complexity? it can't be o(1), right?
r/learnpython on Reddit: What is Python's list.append() method WORST Time Complexity? It can't be O(1), right?
October 26, 2022 -

I know that lists in Python are implemented using arrays that store addresses to the information. Therefore, after several appends, when an array is loaded, it needs to reserve a new space and copy the entire array of addresses to the new place.

I've read on Stackoverflow that in Python Array doubles in size when run of space. So basically it has to copy all addresses log(n) times.

The bigger the list, the more copying it will need to do. So how can append operation have a Constant Time Complexity O(1) if it has some dependence on the array size

I assume since it copies addresses, not information, it shouldn't take long, python takes only 8 bytes for address after all. Moreover, it does so very rarely. Does that mean that O(1) is the average time complexity? Is my assumption right?

Top answer
1 of 4
4
I've read on Stackoverflow that in Python Array doubles in size when run of space It's actually not double, but it does increase proportional to the list size (IIRC it's about 12%, though there's some variance at smaller sizes). This does result in the same asymptotics though, so I'll assume doubling in the following description for simplicity. So basically it has to copy all addresses log(n) times. Not quite. Suppose we're appending n items to an empty vector. We will indeed do log(n) resizes, so you might think "Well, resizes are O(n), so log(n) resizes is n log(n) operations, which if we amortize over the n appends we did means n log(n)/n, or log(n) per append". However, there's a flaw in this analysis: we do not copy "all addresses" each of those times. Ie. the copies are not O(n). Sure, the last copy we do will involve copying n items, but the one before it only copied n/2, and so on. So we actually do 1 + 2 + 4 + ... + n copies, which sums to 2n-1. Divide that by n and you get ~2 operations per append - a constant. I assume since it copies addresses, not information We are indeed only copying the pointer, but this doesn't really matter for the complexity analysis. Even if it was copying a large structure, that'd only increase the time by a constant factor. Does that mean that O(1) is the average time complexity? It's the amortized worst case complexity (ie. what happens over a large number of operations). While any one operation can indeed end up doing O(n) operations, there's an important distinction that over a large number of operations, you are guaranteed to only be O(1), which is a distinction just talking about average case wouldn't capture.
2 of 4
2
Personally, I thought that lists worked as double LinkedLists, so insert time was O(1) But if it works as a dynamic array, time complexity should be amortized time, ie, close to O(1) but not quite
🌐
DEV Community
dev.to › wnleao › python-deque-vs-list-time-comparison-5ch4
Python deque vs list: a time comparison - DEV Community
April 10, 2022 - In python, list operations pop from the end and append will also have time complexity O(1). However, list operations pop from the start and insert to the start will have time complexity of O(n), and there lies the big difference from deque and list.