It's amortized O(1), not O(1).

Let's say the list reserved size is 8 elements and it doubles in size when space runs out. You want to push 50 elements.

The first 8 elements push in O(1). The nineth triggers reallocation and 8 copies, followed by an O(1) push. The next 7 push in O(1). The seventeenth triggers reallocation and 16 copies, followed by an O(1) push. The next 15 push in O(1). The thirty-third triggers reallocation and 32 copies, followed by an O(1) push. The next 31 push in O(1). This continues as the size of list is doubled again at pushing the 65th, 129th, 257th element, etc..

So all of the pushes have O(1) complexity, we had 64 copies at O(1), and 3 reallocations at O(n), with n = 8, 16, and 32. Note that this is a geometric series and asymptotically equals O(n) with n = the final size of the list. That means the whole operation of pushing n objects onto the list is O(n). If we amortize that per element, it's O(n)/n = O(1).

Answer from rlbond on Stack Overflow
Top answer
1 of 3
208

It's amortized O(1), not O(1).

Let's say the list reserved size is 8 elements and it doubles in size when space runs out. You want to push 50 elements.

The first 8 elements push in O(1). The nineth triggers reallocation and 8 copies, followed by an O(1) push. The next 7 push in O(1). The seventeenth triggers reallocation and 16 copies, followed by an O(1) push. The next 15 push in O(1). The thirty-third triggers reallocation and 32 copies, followed by an O(1) push. The next 31 push in O(1). This continues as the size of list is doubled again at pushing the 65th, 129th, 257th element, etc..

So all of the pushes have O(1) complexity, we had 64 copies at O(1), and 3 reallocations at O(n), with n = 8, 16, and 32. Note that this is a geometric series and asymptotically equals O(n) with n = the final size of the list. That means the whole operation of pushing n objects onto the list is O(n). If we amortize that per element, it's O(n)/n = O(1).

2 of 3
61

If you look at the footnote in the document you linked, you can see that they include a caveat:

These operations rely on the "Amortized" part of "Amortized Worst Case". Individual actions may take surprisingly long, depending on the history of the container.

Using amortized analysis, even if we have to occasionally perform expensive operations, we can get a lower bound on the 'average' cost of operations when you consider them as a sequence, instead of individually.

So, any individual operation could be very expensive - O(n) or O(n^2) or something even bigger - but since we know these operations are rare, we guarantee that a sequence of O(n) operations can be done in O(n) time.

🌐
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
For example, the time complexity of the Python list.append() operation is O(1), which means that the operation takes a constant amount of time, regardless of the size of the list.
Discussions

python - Time complexity of appending a list to a list - Stack Overflow
I understand the amortized complexity of appending an element to a list is O(1) but what is the time complexity of appending a list to a list? For clarification: Appending an element to a list list... 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
python - What is the time complexity for appending an element to a list? - Stack Overflow
What is the time complexity for appending an element to a list in Python? More on stackoverflow.com
🌐 stackoverflow.com
What is Python's list.append() method WORST Time Complexity? It can't be O(1), right?
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. More on reddit.com
🌐 r/learnpython
11
3
October 26, 2022
People also ask

How can I optimize list operations in Python?
A: To optimize list operations, consider using data structures that better fit your use case, such as collections.deque for quick appends from both ends or numpy arrays for numerical data.
🌐
sqlpey.com
sqlpey.com › python › why-python-list-append-time-complexity
Top 5 Reasons Why Python's List Append Method Has O(1) Amortized ...
What is amortized time complexity?
A: Amortized time complexity is a method of analyzing the performance of algorithms where the average time per operation is considered over a series of operations, rather than each individual operation.
🌐
sqlpey.com
sqlpey.com › python › why-python-list-append-time-complexity
Top 5 Reasons Why Python's List Append Method Has O(1) Amortized ...
Why does the append method sometimes take longer?
A: The append method may take longer during specific operations due to the need for reallocation and copying of elements when the underlying array runs out of space.
🌐
sqlpey.com
sqlpey.com › python › why-python-list-append-time-complexity
Top 5 Reasons Why Python's List Append Method Has O(1) Amortized ...
🌐
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
🌐
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.
🌐
Scaler
scaler.com › home › topics › python › append in python
Python List append() Method with Examples - Scaler Topics
May 16, 2023 - In that scenario, the previous elements are copied to this new memory space, and new elements are appended to the list. So, this is considered as the worst case for appending any element to the list and the time complexity for this worst case is O(N) where N is the size of the original list.
Find elsewhere
🌐
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.
🌐
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...
🌐
Reddit
reddit.com › r/learnprogramming › time complexity of python list comprehension then list[i] = value vs. list = [] then list.append(value)
r/learnprogramming on Reddit: Time Complexity of Python list comprehension then list[i] = value vs. list = [] then list.append(value)
September 26, 2021 -

Let's say we are writing a function that we know the length of the output list == length of the input list. All we need to do is to insert some value to the output list and return it. I'd like to know if one approach's time complexity is better than another?

First approach:

def someFunc(inputArray):
    result = [1 for _ in inputArray]
    for i in range(len(inputArray)):
        someValue = 100
        result[i] = someValue

vs.

def someFunc(inputArray):
    result = []
    for i in range(len(inputArray)):
        someValue = 100
        result.append(someValue)

The first approach `result[i] = someValue` is O(1) operation, however, is is list comprehension O(n) ? if that's the case then the overall algorithm would be O(2n) time?

The second approach `result.append(someValue)` can be view as O(1) ? That leads to the overall algo time complexity O(n)?

Does that mean in terms of time complexity, second approach is better than first approach? Or not?

Top answer
1 of 3
4
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.
2 of 3
1
Yes, the Time Complexity of the list comprehension is O(n). You literally iterate over every list element, so if the list has n elements, then you're doing n iterations. It's going to be a little more efficient than a for a loop though. Because it's implemented in the C language and better optimized But if we are talking about Asymptotic Growth(which Big O is about). Then the Time Complexity is going to be the same for both the for loop and the list comprehension. As for the actual code you sent. In the first version, you're literally iterating over a list two times. Which kind of doesn't make sense, you could just do [100 for _ in inputArray] and omit the second loop. You can even call functions, use if-else statements from the list comprehensions, and many other things But to answer your question directly, yes it's time Complexity is n+n or O(2n). BUT 2 is constant, which isn't going to affect the Complexity Growth much. Therefore it's not considered, since it doesn't matter that much. So Asymptotic Growth is still considered O(n) With the second version, your assumption is right. Appending to the list has a time complexity of O(1). Since the list size doesn't matter for this operation. Just for your information, removing elements from the list is a very different matter. If you're removing by value or by index from the list, this operation has the worst time complexity of O(n). Because if you removed the first element for example, then under the hood, the computer has to move every single element(n-1 elements) to the left. But it's not the case with the append operation, since you simply add a new element to the end of the list and nothing else is moving. Poping the last element is also O(1) since you just remove one element from the end, and everything stays where it is
🌐
sqlpey
sqlpey.com › python › why-python-list-append-time-complexity
Top 5 Reasons Why Python's List Append Method Has O(1) Amortized Time Complexity
November 24, 2024 - Explore the reasons behind Python's list append method achieving O(1) time complexity and how amortized analysis plays a crucial role.
🌐
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 - In the worst case, where the element ... or removing an element at the end of a Python list is an efficient operation with constant time complexity....
🌐
Finxter
blog.finxter.com › home › learn python blog › python list append() method
Python List append() Method - Be on the Right Side of Change
June 19, 2021 - By using the list concatenation operation, you can create a new list rather than appending the element to an existing list. Time Complexity: The append() method has constant time complexity O(1).
🌐
CSDN
devpress.csdn.net › python › 63044f4b7e66823466199792.html
Why is the time complexity of python's list.append() method O(1)?_python_Mangs-Python
August 23, 2022 - Answer a question As seen in the documentation for TimeComplexity, Python's list type is implemented is using an array. So if an array is being used and we do a few appends, eventually you will have t Mangs Python
🌐
Medium
medium.com › analytics-vidhya › amortized-runtime-analysis-for-python-lists-35e935e290db
Amortized Runtime analysis for python Lists | by Shrutika Poyrekar | Analytics Vidhya | Medium
April 26, 2020 - We can now say that appending an item runs in O(n), i.e. linear time on average. This is called as amortized time complexity. Thus, the way to analyze the whole operation (inserting n objects) instead of one operation alone is called amortized ...
🌐
YouTube
youtube.com › anthonywritescode
how is list append possibly O(1)? (beginner - intermediate) anthony explains #466 - YouTube
today I go over how list / vector / arraylist is O(1) -- or well "amortized" O(1) and what that means!playlist: https://www.youtube.com/playlist?list=PLWBKAf...
Published   August 22, 2022
Views   3K
🌐
Runestone Academy
runestone.academy › ns › books › published › pythonds3 › AlgorithmAnalysis › Lists.html
2.6. Lists — Problem Solving with Algorithms and Data Structures 3rd edition
After thinking carefully about Table 2, you may be wondering about the two different times for pop. When pop is called on the end of the list it takes \(O(1)\), but when pop is called on the first element in the list—or anywhere in the middle it—is \(O(n)\) The reason for this lies in how Python chooses to implement lists.
🌐
Bradfield CS
bradfieldcs.com › algos › analysis › performance-of-python-types
Performance of Python Types
However, the expansion rate is cleverly chosen to be three times the previous size of the array; when we spread the expansion cost over each additional append afforded by this extra space, the cost per append is ... O(1)O(1) on an amortized basis. ... Popping from a Python list is typically performed from the end but, by passing an index, you can pop from a specific position.
🌐
Unstop
unstop.com › home › blog › python list append() | syntax & working (with example codes)
Python List append() | Syntax & Working (With Example Codes)
February 4, 2025 - In most cases, appending an element takes the same amount of time, regardless of the size of the list. This is because Python lists are implemented as dynamic arrays, which allow for efficient addition of elements to the end of the list.