Python .extend(): How to Merge a List’s Items Into Another List
The `.extend()` method in Python adds each element of an iterable to the end of an existing list, in place. If you have `[1, 2]` and you extend it with `[3, 4]`, you get `[1, 2, 3, 4]` — the items from the second list are unpacked and tacked on individually, not nested. It is one of the most useful list methods in the language, and also one of the most commonly confused with `append()`. This guide settles that confusion for good, with heavy code examples and their exact output.
Key Takeaways
• `.extend(iterable)` adds each item from the iterable to the end of the list, in place.
• It modifies the original list and returns `None` — never assign its result.
• `extend()` accepts any iterable: lists, tuples, sets, ranges, and strings.
• A string is iterable, so `.extend(‘hi’)` adds `’h’` and `’i’` — not the word `’hi’`.
• The one-line rule: `append()` adds one thing whole, `extend()` adds many items unpacked.
What does the .extend() method do in Python?
The `.extend()` method takes one argument — an iterable — and appends every element of that iterable to the list it is called on. The change happens in place, meaning the original list object is modified directly rather than a new list being created.
“`python numbers = [1, 2] numbers.extend([3, 4]) print(numbers) “`
Output:
“` [1, 2, 3, 4] “`
Notice that `3` and `4` were added as separate elements. The list grew by two items, not by one. This is the defining behavior of `extend()`: it treats its argument as a collection and merges that collection’s items into the target list.
You can extend a list with another list of any size, and the items are added in order:
“`python shopping = [“milk”, “eggs”] shopping.extend([“bread”, “butter”, “jam”]) print(shopping) “`
Output:
“` [‘milk’, ‘eggs’, ‘bread’, ‘butter’, ‘jam’] “`
The list `shopping` now contains all five items. The original two stayed in front, and the three new ones were appended in the order they appeared in the iterable.
What is the difference between extend() and append()?
This is the single most important comparison to understand, and it trips up nearly every beginner. The two methods look similar — both add to the end of a list — but they behave fundamentally differently.
- `append(x)` adds `x` as a single element, no matter what `x` is. If `x` is a list, the whole list becomes one nested element.
- `extend(iterable)` adds each element of `iterable` separately. The iterable is unpacked.
Watch what happens when you give both methods the same list argument:
“`python a = [1, 2] a.append([3, 4]) print(a)
b = [1, 2] b.extend([3, 4]) print(b) “`
Output:
“` [1, 2, [3, 4]] [1, 2, 3, 4] “`
With `append([3, 4])`, the list `[3, 4]` is added as one item — a list nested inside another list. The result has three elements: `1`, `2`, and the list `[3, 4]`. With `extend([3, 4])`, the two numbers are added individually, producing four flat elements.
Here is the comparison in table form:
| Method | What it does | `[1, 2]` + `[3, 4]` becomes | Length change |
|---|---|---|---|
| `append([3, 4])` | Adds the argument as one element | `[1, 2, [3, 4]]` | +1 |
| `extend([3, 4])` | Adds each element of the argument | `[1, 2, 3, 4]` | +2 |
A second view, by effect on the list:
| You want to… | Use | Example |
|---|---|---|
| Add one value (or keep a list whole) | `append()` | `lst.append(item)` |
| Merge another collection’s items in | `extend()` | `lst.extend(other)` |
| Insert at a specific index | `insert()` | `lst.insert(0, item)` |
The `extend()`-vs-`append()` confusion has a precise, memorable resolution that you can carry forever. `append()` adds its argument as a SINGLE element, no matter what it is. `extend()` treats its argument as a COLLECTION and adds each element. So `mylist.append([1, 2])` nests the list — you get `[…, [1, 2]]`, one new element that happens to be a list — while `mylist.extend([1, 2])` unpacks it — you get `[…, 1, 2]`, two new elements. The trap that bites everyone: `extend()` takes ANY iterable and iterates it, so `mylist.extend(‘hi’)` does not add the string `’hi’` — it adds `’h’` and `’i’` as separate characters, because a string is iterable. The rule is: use `append` when you want to add ONE thing (preserving it whole, even if it is a list), and use `extend` when you want to MERGE another collection’s items in. And remember `extend` will happily explode a string into letters, so if you meant to add the whole string as one item, that is an `append`. “One item vs many items” is the entire distinction, and “is my argument something I want kept whole or unpacked?” is the question that picks the right method every single time.
Does extend() modify the list in place or return a new one?
`.extend()` modifies the list in place and returns `None`. This is the same gotcha that catches people with `append()`, `sort()`, and `reverse()`. If you try to capture the result of `extend()` in a variable, you will get `None` instead of your list.
“`python colors = [“red”, “green”] result = colors.extend([“blue”, “yellow”]) print(result) print(colors) “`
Output:
“` None [‘red’, ‘green’, ‘blue’, ‘yellow’] “`
The variable `result` is `None` because `extend()` returns nothing. The actual change lives in `colors`, which was mutated directly. The correct pattern is to call `extend()` as a statement on its own line and then use the original list:
“`python colors = [“red”, “green”] colors.extend([“blue”, “yellow”]) # mutate in place print(colors) # use the original variable “`
Output:
“` [‘red’, ‘green’, ‘blue’, ‘yellow’] “`
If you ever write `mylist = mylist.extend(…)`, you have just thrown away your list and replaced it with `None`. Avoid that.
Can you extend a list with any iterable?
Yes. Unlike a method that only accepts lists, `extend()` works with any iterable: tuples, sets, ranges, dictionary views, generators, and strings. It iterates the argument and adds each yielded item.
“`python data = [1, 2]
data.extend((3, 4)) # tuple print(data)
data.extend({5, 6}) # set (order not guaranteed) print(data)
data.extend(range(7, 10)) # range print(data) “`
Output:
“` [1, 2, 3, 4] [1, 2, 3, 4, 5, 6] [1, 2, 3, 4, 5, 6, 7, 8, 9] “`
The tuple, set, and range were each unpacked into their individual elements. This flexibility is part of what makes `extend()` so handy when you are combining data from different sources.
The string gotcha. Because a string is iterable — iterating it yields one character at a time — extending a list with a string adds each character, not the whole string:
“`python letters = [“a”, “b”] letters.extend(“hi”) print(letters) “`
Output:
“` [‘a’, ‘b’, ‘h’, ‘i’] “`
That is almost never what people expect the first time. If you wanted to add the whole word `”hi”` as a single element, use `append(“hi”)` instead:
“`python words = [“a”, “b”] words.append(“hi”) print(words) “`
Output:
“` [‘a’, ‘b’, ‘hi’] “`
This single example captures the whole `append`-vs-`extend` decision: do you want the string kept whole (`append`) or exploded into characters (`extend`)?
How does extend() compare to the + operator and +=?
There are three common ways to combine lists, and they differ in whether they create a new list or mutate an existing one.
- `+` operator creates a brand-new list and leaves the originals untouched.
- `extend()` mutates the list in place and returns `None`.
- `+=` (augmented assignment) behaves like `extend()` for lists — it mutates in place.
“`python a = [1, 2] b = [3, 4]
c = a + b # + makes a NEW list print(c) print(a) # a is unchanged “`
Output:
“` [1, 2, 3, 4] [1, 2] “`
Now compare with `extend()` and `+=`, both of which change the original:
“`python x = [1, 2] x.extend([3, 4]) # mutate in place print(x)
y = [1, 2] y += [3, 4] # also mutate in place (like extend) print(y) “`
Output:
“` [1, 2, 3, 4] [1, 2, 3, 4] “`
Here is the distinction summarized:
| Approach | Result | Original list | Returns |
|---|---|---|---|
| `a + b` | New list | Unchanged | The new list |
| `a.extend(b)` | Items merged in | Modified | `None` |
| `a += b` | Items merged in | Modified | (statement) |
When performance and memory matter, `extend()` and `+=` are preferable for building up a list incrementally, because they avoid creating a new list object on every operation the way repeated `+` would.
When should you use itertools.chain instead of extend()?
`extend()` is perfect for merging a few iterables into one list. But when you need to iterate over several iterables in sequence without building one big combined list in memory, `itertools.chain` is the better tool. It produces a lazy iterator that yields items from each source in turn.
“`python from itertools import chain
a = [1, 2] b = (3, 4) c = range(5, 7)
for item in chain(a, b, c): print(item, end=” “) “`
Output:
“` 1 2 3 4 5 6 “`
`chain` never builds a combined list — it streams the items. Use `extend()` when you actually want a single list as the result; use `chain()` when you only need to loop over the combined sequence and want to avoid the memory cost of a merged list. If you do want a list from `chain`, you can wrap it: `list(chain(a, b, c))`.
Running real Python workloads? Combining and processing data with `extend()`, generators, and `itertools` is lightweight on small inputs — but production data pipelines need stable, guaranteed resources. DarazHost VPS and dedicated servers give developers a real, controllable Python environment: process and combine data efficiently on guaranteed CPU and memory with full root access. It is the dependable home your Python work needs, backed by 24/7 support so your scripts and services stay up. When you outgrow a laptop, this is the environment to build on. Learn more in our complete guide to hosting for developers.
A quick reference: which list method does what?
When you are deciding how to add data to a list, this table maps the common methods to their effect:
| Method | Effect | Returns |
|---|---|---|
| `list.append(x)` | Adds `x` as one element at the end | `None` |
| `list.extend(iterable)` | Adds each item of `iterable` at the end | `None` |
| `list.insert(i, x)` | Inserts `x` before index `i` | `None` |
| `list + other` | Creates a new combined list | New list |
| `list += other` | Extends `list` in place | (statement) |
| `itertools.chain(*iters)` | Lazily iterates several iterables | Iterator |
For most “add a collection’s items to my list” tasks, `extend()` is exactly the right call.
Frequently asked questions
Does Python’s extend() return the new list? No. `extend()` returns `None`. It modifies the list in place. If you write `result = mylist.extend([1, 2])`, `result` will be `None` and you will lose your reference if you assigned over the original variable. Call `extend()` as a standalone statement and keep using the original list.
What is the difference between append() and extend() in one sentence? `append()` adds its argument as a single element (so `append([1, 2])` nests the list), while `extend()` adds each element of its argument separately (so `extend([1, 2])` adds two items). One thing vs many things.
Why does extend() split my string into characters? Because a string is an iterable, and `extend()` iterates whatever you pass it. Iterating a string yields its characters one by one, so `mylist.extend(‘hi’)` adds `’h’` and `’i’`. To add the whole string as one element, use `mylist.append(‘hi’)`.
Is extend() faster than using a loop with append()? Generally yes. `extend()` is implemented in C and adds all items in one operation, which is faster than calling `append()` repeatedly in a Python `for` loop for the same items. When merging an iterable, prefer `extend()`.
Can I extend a list with a dictionary? Yes, but be aware of what gets added. Extending with a dict adds its keys (because iterating a dict yields keys). Use `mylist.extend(mydict.values())` if you want the values, or `mylist.extend(mydict.items())` for key-value tuples.