append vs extend vs + for lists
February 12, 2026
When combining lists in Python, append is not the same as extend or +.
append(x)
It adds the entire x as one single element to the list , and it can create nesting if x is a list or a tuple.
feed = []
x = [(1,"a"), (2,"b")]
feed.append(x)
# feed = [[(1,"a"), (2,"b")]] extend(iterable)
Takes all elements from another list and adds them into our list (in-place).. meaning doesnt create a new list, but modifies the existing list.
feed = []
x = [(1,"a"), (2,"b")]
feed.extend(x)
# feed = [(1,"a"), (2,"b")] +
Concatenates the new list and returns a new list.
feed = [(0, "Z")]
feed = feed + [(1, "a"), (2, "b")]
# feed = [(0, "Z"), (1, "a"), (2, "b")] # new list feed is created - Use
appendwhen we want to add one-one items. - Use
extend(or+=) when we want to add many items from another list. - Use
+when we want a new combined list.
Why it matters (sorting example)
If our list should be a flat list of tuples like [(time, id), ...], you want:
feed.extend(self.tweets[f]) # or feed += self.tweets[f]
feed.sort(key=lambda x: x[0], reverse=True)If we accidentally do append, we'll get a list-of-lists like this :
feed.append(self.tweets[f])
# feed = [[(time, id), ...], [(time, id), ...], ...]and sorting becomes annoying.
This design twitter question , had some edge cases which helped me understand this.