Home »
Python
Python - Join Two Lists
Last Updated : May 01, 2025
In Python, joining two is easy using the +
operator or the extend()
method. Both approaches combine the elements of both lists into one.
In this chapter, we will learn joining lists using these two and other approaches with the help of examples.
Joining Two Lists Using + Operator
The +
operator can be used to concatenate two lists, effectively joining them into a single list.
Example
In this example, we are joining two lists of cities using the +
operator.
# Creating two lists of cities
cities_1 = ["New York", "London", "Paris"]
cities_2 = ["Berlin", "Tokyo", "Sydney"]
# Joining the lists using the + operator
combined_cities = cities_1 + cities_2
# Displaying the combined list
print(combined_cities)
The output of the above code would be:
['New York', 'London', 'Paris', 'Berlin', 'Tokyo', 'Sydney']
Joining Two Lists Using extend() Method
The extend()
method appends all elements from one list to another. Unlike the +
operator, it modifies the original list in-place.
Example
In this example, we are joining two lists of cities using the extend()
method.
# Creating two lists of cities
cities_1 = ["New York", "London", "Paris"]
cities_2 = ["Berlin", "Tokyo", "Sydney"]
# Extending cities_1 with cities_2
cities_1.extend(cities_2)
# Displaying the extended list
print(cities_1)
The output of the above code would be:
['New York', 'London', 'Paris', 'Berlin', 'Tokyo', 'Sydney']
Joining Two Lists Using append() Method in a Loop
While the extend()
method appends all elements at once, you can also use the append()
method in a loop to join two lists one element at a time.
Example
In this example, we are using a loop to append each element from one list to another.
# Creating two lists of cities
cities_1 = ["New York", "London", "Paris"]
cities_2 = ["Berlin", "Tokyo", "Sydney"]
# Looping through cities_2 and
# appending each city to cities_1
for city in cities_2:
cities_1.append(city)
# Displaying the joined list
print(cities_1)
The output of the above code would be:
['New York', 'London', 'Paris', 'Berlin', 'Tokyo', 'Sydney']
Joining Two Lists Using List Comprehension
You can use list comprehension to join two lists. This is useful when you want to apply a condition or transformation while joining.
Example
In this example, we are using list comprehension to join two lists of cities.
# Creating two lists of cities
cities_1 = ["New York", "London", "Paris"]
cities_2 = ["Berlin", "Tokyo", "Sydney"]
# Joining the lists using
# list comprehension
combined_cities = [city for city in cities_1] + [city for city in cities_2]
# Displaying the combined list
print(combined_cities)
The output of the above code would be:
['New York', 'London', 'Paris', 'Berlin', 'Tokyo', 'Sydney']
Joining Two Lists Using itertools.chain() Method
The chain()
function from the itertools
module can be used to join multiple iterables (like lists) into a single iterable.
Example
In this example, we are using the chain()
method from the itertools
module to join two lists.
import itertools
# Creating two lists of cities
cities_1 = ["New York", "London", "Paris"]
cities_2 = ["Berlin", "Tokyo", "Sydney"]
# Joining the lists using
# itertools.chain()
combined_cities = list(itertools.chain(cities_1, cities_2))
# Displaying the combined list
print(combined_cities)
The output of the above code would be:
['New York', 'London', 'Paris', 'Berlin', 'Tokyo', 'Sydney']
Exercise
Select the correct option to complete each statement about joining two lists in Python.
- Which operator is used to join two lists in Python?
- What will be the result of
list1 = [1, 2]
and list2 = [3, 4]
, and the operation list1 + list2
?
- Which method can be used to extend the first list by appending all the items from the second list?
Advertisement
Advertisement