W3docs

How to Join Lists in Python

Learn every way to join or merge Python lists: the + operator, extend(), unpacking, itertools.chain, and how str.join() turns a list into a string.

Python gives you several ways to combine lists and to turn a list of strings into a single string. This page covers both tasks clearly:

  • Joining lists — merging two or more lists into one new list (using +, extend(), unpacking, or itertools.chain).
  • Joining list elements into a string — using the str.join() method, which concatenates the items of a list into a delimited string.

Understanding the difference between these two operations prevents a common source of confusion for beginners.

Joining Two Lists into One

Using the + Operator

The simplest way to merge two lists is the + operator. It returns a new list containing all elements from both operands without changing the originals.

list1 = [1, 2, 3]
list2 = [4, 5, 6]
combined = list1 + list2
print(combined)

Output:

[1, 2, 3, 4, 5, 6]

You can chain + to merge more than two lists in one expression: a + b + c.

Using the extend() Method

extend() appends all elements of one list to the end of another in place. Unlike +, it modifies the original list and does not create a new one.

list1 = [1, 2, 3]
list2 = [4, 5, 6]
list1.extend(list2)
print(list1)

Output:

[1, 2, 3, 4, 5, 6]

Use extend() when you do not need to keep the original list1 intact and want to avoid creating an extra copy in memory.

extend() vs append(): append() adds its argument as a single element, so list1.append(list2) produces [1, 2, 3, [4, 5, 6]] — a nested list, not a merged one. Always use extend() when you want to flatten the second list into the first.

Using Unpacking (* Operator)

Python 3.5 and later allow the starred unpacking syntax inside a list literal. This is concise and works with any number of iterables in a single expression.

list1 = [1, 2, 3]
list2 = [4, 5, 6]
combined = [*list1, *list2]
print(combined)

Output:

[1, 2, 3, 4, 5, 6]

You can also insert extra elements inline: [0, *list1, *list2, 7].

Using itertools.chain()

itertools.chain() from the standard library joins any number of iterables lazily — no intermediate list is created until you request the values. This is the most memory-efficient option when you are processing large sequences.

import itertools

list1 = [1, 2, 3]
list2 = [4, 5, 6]
combined = list(itertools.chain(list1, list2))
print(combined)

Output:

[1, 2, 3, 4, 5, 6]

Pass itertools.chain(*nested) to flatten a list of lists in one call.

Joining List Elements into a String with str.join()

str.join() is a string method — it is called on the delimiter string and takes an iterable as its argument. It returns a single string with all elements concatenated, separated by the delimiter.

delimiter.join(iterable)

Basic Example

python— editable, runs on the server

Output:

apple, banana, cherry

Pass an empty string '' as the delimiter to concatenate with no separator at all.

Common Delimiters

DelimiterExpressionResult
Comma-space', '.join(['a', 'b', 'c'])a, b, c
Space' '.join(['Python', 'is', 'great'])Python is great
Hyphen'-'.join(['2024', '01', '15'])2024-01-15
Newline'\n'.join(['line one', 'line two'])multi-line block
No separator''.join(['H', 'i', '!'])Hi!

Joining a List of Numbers

str.join() requires every element to be a string. Passing integers directly raises a TypeError. Convert them first with map(str, ...) or a generator expression.

nums = [10, 20, 30]
result = ', '.join(map(str, nums))
print(result)

Output:

10, 20, 30

Using a generator expression achieves the same result and lets you format each number as you go:

python— editable, runs on the server

Output:

12345

Building Multi-line Strings

'\n'.join() is the idiomatic way to build a multi-line string from a list of lines without trailing newlines.

lines = ['line one', 'line two', 'line three']
block = '\n'.join(lines)
print(block)

Output:

line one
line two
line three

Choosing the Right Approach

GoalBest method
Merge two lists into a new list+ operator
Add all items of one list into anotherextend()
Combine multiple iterables without an extra copyitertools.chain()
Combine inside a literal or with extra items[*a, *b] unpacking
Turn a list of strings into a delimited stringstr.join()
Turn a list of numbers into a stringstr.join(map(str, lst))

Practice

Practice
Which of the following ways can be used to join two lists in Python?
Which of the following ways can be used to join two lists in Python?
Was this page helpful?