Python Join Lists

Combining two or more lists into a single list is a fundamental operation in Python programming. Python join lists using several built-in techniques, and each approach has its own strengths depending on your situation. Whether you need to merge two small lists or concatenate dozens of large lists together, Python provides clean and efficient ways to get the job done. Knowing how to join lists in Python will help you work with data from multiple sources, build up results incrementally, and write more flexible programs.

Python does not have a single dedicated join method for lists like it does for strings. Instead, you can join lists in Python using operators, methods, and functions that each behave slightly differently. Some create a brand new list while others modify an existing list in place. Understanding these differences helps you choose the right approach for your specific use case.

Join Lists Using the + Operator

The + operator is the simplest and most intuitive way to join lists in Python. It takes two lists and returns a brand new list containing all elements from both lists in order.

fruits = ["apple", "banana", "cherry"]
vegetables = ["carrot", "spinach", "broccoli"]
combined = fruits + vegetables
print(combined)
print("Original fruits:", fruits)
Output
['apple', 'banana', 'cherry', 'carrot', 'spinach', 'broccoli']
Original fruits: ['apple', 'banana', 'cherry']

The + operator created a new list with all six items while leaving the original lists unchanged. This is important because it means you can join lists in Python without losing your source data. You can also chain multiple + operations together to join more than two lists at once.

list_a = [1, 2]
list_b = [3, 4]
list_c = [5, 6]
result = list_a + list_b + list_c
print(result)
Output
[1, 2, 3, 4, 5, 6]

Chaining the + operator works well for a small number of lists. Each + operation creates a new intermediate list, so for joining many lists, other methods may be more efficient.

Join Lists Using the extend Method

The extend method adds all elements from one list to the end of another list. Unlike the + operator, extend modifies the original list in place rather than creating a new one. This makes it a good choice to join lists in Python when you want to build up a single list by adding elements from other lists.

colors = ["red", "green", "blue"]
more_colors = ["yellow", "purple", "orange"]
colors.extend(more_colors)
print("Extended:", colors)
print("Source unchanged:", more_colors)
Output
Extended: ['red', 'green', 'blue', 'yellow', 'purple', 'orange']
Source unchanged: ['yellow', 'purple', 'orange']

The extend method appended all three new colors to the original list. The source list passed to extend remained unchanged. Since extend works in place, it does not create a new list object, which makes it more memory efficient than the + operator when you do not need to preserve the original list.

numbers = [10, 20]
numbers.extend([30, 40])
numbers.extend([50, 60])
print(numbers)
Output
[10, 20, 30, 40, 50, 60]

You can call extend multiple times to join several lists in Python into a single growing list. Each call appends the new elements directly to the end of the existing list.

Join Lists Using the += Operator

The += operator is shorthand that works just like extend. It modifies the list on the left side by appending all elements from the list on the right side. Many developers prefer this syntax to join lists in Python because it is concise and readable.

letters = ["a", "b", "c"]
letters += ["d", "e", "f"]
print(letters)
Output
['a', 'b', 'c', 'd', 'e', 'f']

The += operator modified the original list in place, just like extend. For all practical purposes, writing letters += another_list is equivalent to writing letters.extend(another_list). Both are valid ways to join lists in Python when you want to modify the list directly.

Join Lists Using Unpacking

The unpacking operator provides a modern and flexible way to join lists in Python. By placing an asterisk before each list inside square brackets, you unpack all elements into a new list. This syntax was introduced in PEP 448 and works in Python 3.5 and later.

first = [1, 2, 3]
second = [4, 5, 6]
third = [7, 8, 9]
merged = [*first, *second, *third]
print(merged)
Output
[1, 2, 3, 4, 5, 6, 7, 8, 9]

Unpacking makes it easy to join multiple lists in Python in a single expression. You can also mix individual elements with unpacked lists, which gives you extra flexibility.

start = [1, 2]
end = [8, 9]
combined = [0, *start, 5, *end, 10]
print(combined)
Output
[0, 1, 2, 5, 8, 9, 10]

The unpacking syntax lets you insert individual values between unpacked lists, making it one of the most versatile ways to join lists in Python. This is something you cannot do as cleanly with the + operator or extend.

Join Lists Using itertools.chain

The itertools.chain function is designed for joining multiple iterables together efficiently. It creates an iterator that yields elements from each iterable one after another without building intermediate lists in memory.

from itertools import chain

list1 = [10, 20, 30]
list2 = [40, 50, 60]
list3 = [70, 80, 90]
combined = list(chain(list1, list2, list3))
print(combined)
Output
[10, 20, 30, 40, 50, 60, 70, 80, 90]

The chain function is especially useful when you need to join many lists in Python or when working with large datasets. Since it produces an iterator rather than building the entire result in memory at once, it can be significantly more memory efficient for large-scale operations.

Join Lists Using a Loop

Using a for loop to join lists in Python gives you the most control over the process. You can add conditions, transform elements, or handle special cases while merging lists together.

primary = ["Python", "Java", "C++"]
secondary = ["Ruby", "Go", "Rust"]
joined = []
for item in primary:
    joined.append(item)
for item in secondary:
    joined.append(item)
print(joined)
Output
['Python', 'Java', 'C++', 'Ruby', 'Go', 'Rust']

While a loop is more verbose than other approaches, it lets you add logic during the join. For example, you can skip duplicates or transform elements as you merge.

list_x = [1, 2, 3, 4, 5]
list_y = [4, 5, 6, 7, 8]
unique_joined = list(list_x)
for item in list_y:
    if item not in unique_joined:
        unique_joined.append(item)
print(unique_joined)
Output
[1, 2, 3, 4, 5, 6, 7, 8]

This loop-based approach to join lists in Python removed duplicates while preserving the order of elements. This is useful when you need a union of two lists rather than a simple concatenation.

Join Lists Using a List Comprehension

A list comprehension can flatten a list of lists into a single list. This is a compact way to join lists in Python when your source lists are already collected inside another list.

lists = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
flat = [item for sublist in lists for item in sublist]
print(flat)
Output
[1, 2, 3, 4, 5, 6, 7, 8, 9]

The nested comprehension iterates over each sublist and then over each item within that sublist, collecting everything into a single flat list. This technique to join lists in Python is concise but can be harder to read for beginners. The equivalent loop version would use two nested for loops with an append call.

Join Lists of Different Data Types

Python lists can contain any mix of data types, and all the join methods work regardless of what types the lists contain. You can freely join lists in Python that hold numbers, strings, booleans, or any other objects.

numbers = [1, 2, 3]
words = ["hello", "world"]
mixed = [True, None, 3.14]
everything = numbers + words + mixed
print(everything)
print("Length:", len(everything))
Output
[1, 2, 3, 'hello', 'world', True, None, 3.14]
Length: 8

Python does not require lists to have matching types when you join them. The resulting list simply contains all elements from all source lists in the order they were joined.

Full Working Example

This example demonstrates all the major techniques to join lists in Python, showing how each method works and when to use it.

from itertools import chain

print("=== + Operator ===")
fruits = ["apple", "banana"]
berries = ["strawberry", "blueberry"]
all_fruits = fruits + berries
print("Joined:", all_fruits)
print("Original preserved:", fruits)

print("\n=== extend() Method ===")
base = [10, 20, 30]
extra = [40, 50, 60]
base.extend(extra)
print("Extended:", base)

print("\n=== += Operator ===")
letters = ["a", "b"]
letters += ["c", "d"]
print("After +=:", letters)

print("\n=== Unpacking ===")
first = [1, 2]
second = [3, 4]
third = [5, 6]
unpacked = [*first, *second, *third]
print("Unpacked:", unpacked)

print("\n=== Unpacking with Extra Elements ===")
mixed = [0, *first, 99, *second]
print("Mixed unpack:", mixed)

print("\n=== itertools.chain ===")
a = ["x", "y"]
b = ["z", "w"]
c = ["v", "u"]
chained = list(chain(a, b, c))
print("Chained:", chained)

print("\n=== Loop with Duplicate Removal ===")
list1 = [1, 2, 3, 4]
list2 = [3, 4, 5, 6]
unique = list(list1)
for item in list2:
    if item not in unique:
        unique.append(item)
print("Unique join:", unique)

print("\n=== List Comprehension Flatten ===")
nested = [[10, 20], [30, 40], [50, 60]]
flat = [item for sublist in nested for item in sublist]
print("Flattened:", flat)

print("\n=== Joining Multiple Types ===")
nums = [1, 2, 3]
words = ["python", "code"]
bools = [True, False]
combined = nums + words + bools
print("Combined:", combined)
print("Total items:", len(combined))
Output
=== + Operator ===
Joined: ['apple', 'banana', 'strawberry', 'blueberry']
Original preserved: ['apple', 'banana']

=== extend() Method ===
Extended: [10, 20, 30, 40, 50, 60]

=== += Operator ===
After +=: ['a', 'b', 'c', 'd']

=== Unpacking ===
Unpacked: [1, 2, 3, 4, 5, 6]

=== Unpacking with Extra Elements ===
Mixed unpack: [0, 1, 2, 99, 3, 4]

=== itertools.chain ===
Chained: ['x', 'y', 'z', 'w', 'v', 'u']

=== Loop with Duplicate Removal ===
Unique join: [1, 2, 3, 4, 5, 6]

=== List Comprehension Flatten ===
Flattened: [10, 20, 30, 40, 50, 60]

=== Joining Multiple Types ===
Combined: [1, 2, 3, 'python', 'code', True, False]
Total items: 7