Python List append vs extend vs insert: Differences, Pitfalls and Speed

append, extend and insert all make a Python list longer, and all three change the list in place. The difference is what they add and where: append adds one object at the end, extend adds every item of an iterable at the end, and insert adds one object at the position you choose. Picking the wrong one rarely raises an error, which is exactly why the bugs it causes are hard to spot. This article compares the three methods with real outputs, the classic traps and a measured speed test.
All examples were run on Python 3.13. List methods have behaved this way throughout Python 3.
The short answer
| Method | Adds | Where | Typical cost |
|---|---|---|---|
lst.append(x) | one object, x itself | at the end | constant on average |
lst.extend(iterable) | each item of the iterable | at the end | proportional to the items added |
lst.insert(i, x) | one object | before index i | proportional to the items after i |
The costs in the last column are the ones listed on the TimeComplexity page of the Python wiki for CPython: appending is "amortised" constant time, while inserting has to shift every element that follows the insertion point.
append: one object at the end
append takes exactly one argument and puts that object, whatever it is, at the end of the list. The Python tutorial describes it as the equivalent of a[len(a):] = [x].
a = [1, 2, 3]
a.append([4, 5])
print(a)
[1, 2, 3, [4, 5]]
The list grew by one item, not two: the last item is itself a list. That nested result is what you want when you build a list of rows or records, and the most common mistake when you meant to merge two lists.
extend: every item of an iterable
extend loops over its argument and appends each item in turn. The argument can be any iterable: a list, a tuple, a range, a generator, a set, the keys of a dictionary.
b = [1, 2, 3]
b.extend([4, 5])
print(b)
keys = []
keys.extend({"x": 1, "y": 2})
print(keys)
[1, 2, 3, 4, 5]
['x', 'y']
The second example shows a detail worth remembering: iterating over a dictionary gives its keys, so extend adds the keys, not the values. Use extend(d.values()) or extend(d.items()) when that is what you need.
The string trap
A string is an iterable of characters, so extend splits it:
d = ["a"]
d.extend("bc")
print(d)
e = ["a"]
e.append("bc")
print(e)
['a', 'b', 'c']
['a', 'bc']
If you are adding a single word to a list of words, use append. If you really want to turn a sentence into a list of words, split it first, as explained in our guide to splitting a string into a list.
insert: one object at a chosen position
insert(i, x) places x before the item currently at index i. insert(0, x) adds at the front and insert(len(a), x) is the same as append(x).
c = [1, 2, 3]
c.insert(1, 99)
print(c)
f = [1, 2, 3]
f.insert(100, 4) # index past the end: added at the end
print(f)
f.insert(-1, "x") # negative index: before the last item
print(f)
[1, 99, 2, 3]
[1, 2, 3, 4]
[1, 2, 3, 'x', 4]
Two behaviours surprise people. An index larger than the list does not raise IndexError: the item simply goes at the end. And a negative index counts from the end, so insert(-1, x) puts x before the last item, not after it.
All three return None
The methods change the list in place and return None. Assigning their result is a frequent bug, and it usually surfaces later as a "NoneType object is not subscriptable" error.
g = [1, 2]
result = g.append(3)
print(result, g)
None [1, 2, 3]
If you need a new list and want to keep the original unchanged, use concatenation instead: new = old + [3] builds a separate list.
What about += and slicing?
For lists, a += iterable behaves like a.extend(iterable): it modifies the list in place and accepts any iterable, even a tuple. Slice assignment at the end does the same:
h = [1, 2]
h += (3, 4)
print(h)
i = [1, 2]
i[len(i):] = [3, 4]
print(i)
[1, 2, 3, 4]
[1, 2, 3, 4]
By contrast, a = a + [3, 4] creates a new list and rebinds the name. The difference matters when another variable points to the same list, a situation covered in the copying section of our Python lists guide.
Speed: what we measured
We timed each approach with the standard timeit module, building a list of 100,000 integers on Python 3.13 (best of three runs, on our test machine; your figures will differ, but the proportions hold):
| Approach | Time for 100,000 items |
|---|---|
extend(range(100000)) in one call | about 1.2 ms |
append(i) in a loop | about 2.0 ms |
deque.appendleft(i) in a loop | about 3.1 ms |
insert(0, i) in a loop | about 910 ms |
A single extend beats a loop of append calls because the loop runs in C instead of Python. The real outlier is insert(0, …): every insertion at the front moves all the existing items, so the total work grows with the square of the list size. If your program keeps adding at the front, a collections.deque, whose documentation describes appends and pops "from either side" in approximately constant time, is the right tool.
Which one should you use?
- Adding a single value at the end:
append. - Adding the contents of another list, tuple, range or generator:
extend(or+=). - Adding a list as one element, for example a row in a table:
append. - Adding at a specific position in a short list:
insert. - Adding at the front again and again: a
dequewithappendleft, or build the list in reverse and callreverse()once.
For counting what ends up in the list afterwards, see counting occurrences in a list; for lists of lists, our article on two-dimensional arrays in Python explains why append is the right way to add rows.
Sources
- Python Software Foundation, The Python Tutorial: More on Lists.
- Python Software Foundation, Built-in Types: Mutable Sequence Types.
- Python Wiki, TimeComplexity (cost of list operations in CPython).
- Python Software Foundation, collections: deque objects; timeit.
PythonPython lists, from basics to idioms
A complete guide to Python lists: creating lists, indexing and slicing, adding and removing items (append, extend, insert, pop, remove), sorting, searching, list comprehensions, copying without surprises and the idioms you will use every day.
PythonSplit a string into a list
Split strings into lists in Python: str.split with and without sep, maxsplit, rsplit, splitlines, re.split for multiple delimiters, list(), csv and shlex.
PythonCount word occurrences
Count how often words appear in a Python list with list.count, collections.Counter, dict and defaultdict loops, normalization of case and punctuation, and pandas.