0%

🪄 Merge Lists, Clean & Safe

Joins lists without side effects. No loops. No extend(). No changes. It returns a new list, originals stay safe.
🔮 combined = list1 + list2

The simplest spell in the book. The + operator between two lists creates a brand new list containing all elements from the first list followed by all elements from the second. No original is harmed in this operation. Your source lists remain exactly as they were. Pure. Untouched. Safe.

🕯️ Magic Note

The + operator is overloaded in Python. For numbers it adds. For strings it concatenates. For lists it merges. Behind the scene, Python allocates new memory and copies elements from both lists into a fresh container.

The syntax list1 + list2 works with any two lists regardless of their content types. The result is always a new list. The original lists never change. This is called a pure operation with no side effects.
  • Works with empty lists: [] + [1, 2] returns [1, 2]
  • Can chain multiple lists: a + b + c + d
  • Originals remain unchanged, perfect for immutable workflows
  • Preserves the order of elements from both lists
💡 Use + when you want to keep your original lists intact. Use extend() when you are okay with modifying the first list. Use append() for adding single elements. Each has its own purpose in different rituals.
list1list2Result
[1, 2][3, 4][1, 2, 3, 4]
[“a”, “b”][“c”][“a”, “b”, “c”]
[][5, 6, 7][5, 6, 7]
[True, False][True][True, False, True]
⚠️ The + operator creates a new list by copying all elements. For very large lists (thousands of items), this consumes extra memory. If memory is a concern and you don’t need the originals, consider extend() or itertools.chain().
Examples

Python

# Merge two lists of tasks

morning_tasks = [“write code”, “drink coffee”]

evening_tasks = [“review code”, “conjure ideas”]

all_tasks = morning_tasks + evening_tasks

print(all_tasks)

# Output: [“write code”, “drink coffee”, “review code”, “conjure ideas”]

# morning_tasks and evening_tasks are unchanged

Python

# Chaining three lists together

first = [1, 2]

second = [3, 4]

third = [5, 6]

combined = first + second + third

print(combined)

# Output: [1, 2, 3, 4, 5, 6]

Python

# Mixing different data types

numbers = [10, 20, 30]

words = [“python”, “magic”]

mixed = numbers + words

print(mixed)

# Output: [10, 20, 30, “python”, “magic”]

Common Mistakes
  • Using + between a list and a non list, TypeError: can only concatenate list (not “int”) to list
  • Forgetting that + creates a new list, not modifying the original
  • Confusing + with append() which adds a single element as a nested item

⚡ Whisper

Two streams become one river. No resistance. No loss. Each drop keeps its place. The merge is silent, the originals remain sacred.