I am learning Python and trying to combi

2026-09-17 · Anonymous · Doramagic.ai

Ask

I am learning Python and trying to combine two lists.
I have fruits = ['apple', 'banana'] and more_fruits = ['cherry', 'orange'].
When I ran fruits.append(more_fruits), I expected ['apple', 'banana', 'cherry', 'orange'], but instead I got ['apple', 'banana', ['cherry', 'orange']] with brackets inside brackets!
Can you teach me in a 10-minute micro-goal why append() does this, how extend() works differently, show a runnable demo, and give me a quick try-it challenge to test my understanding?

Answer

I'll read the one-step reference first, then walk through this with you.

**The one-line answer:** `append()` takes **one** thing and adds it as a single item — if you hand it a list, the whole list goes in as one nested box. `extend()` walks the list and pulls each item out flat.

**Tonight's 10-minute goal:** run both on the same pair, see the length difference (3 vs 4), and predict a third case on your own.

**Why you saw nested brackets (with a different pair so the principle is what you learn, not the data):**

`append(x)` — adds one object. Always. If `x` is a list, that list becomes one element of the outer list. It's like putting a sealed box into a bigger box — the box is one item, even though it has things inside.

`extend(iterable)` — walks through the iterable and adds each item one by one. No box, no nesting. The items land next to the existing ones as siblings.

**unnable demo (copy-paste as-is):**

```python
colors = ['red', 'blue']
more_colors = ['green', 'yellow']

# append path
a = colors.copy()
a.append(more_colors)
print("append:", a)
print("length:", len(a)) # 3 — the inner list is ONE item

# extend path
b = colors.copy()
b.extend(more_colors)
print("extend:", b)
print("length:", len(b)) # 4 — each color landed separately
```

You should see:
```
append: ['red', 'blue', ['green', 'yellow']]
length: 3
extend: ['red', 'blue', 'green', 'yellow']
length: 4
```

The length is the smoking gun. If `append` had really merged the two lists, the length would be 4, not 3. It's 3 because the inner list counts as one slot.

**Your 2-minute try-it:** Make `nums = [1, 2]` and `more_nums = [3, 4]`. Before you run anything, on a piece of paper write:

- "After `nums.append(more_nums)` → length is ___"
- "After `nums.extend(more_nums)` → length is ___"
- "After `nums.append(5)` → length is ___ and the last item is ___" *(this one is the trap: a single number, not a list, but append still adds it as one item)*

Then run it, check your predictions, and paste the three outputs back. I'll read what you got and tell you what the next step is.

One tip if you hit an error: most mistakes here are a typo in the dot — `nums.append` not `nums,append`, and the argument inside the parens is exactly one object (a list, a number, or a string).