Ways to join Two Lists in Python
There are several ways to concatenate, or join, two or more lists in Python. One of the easiest ways are by using the plus (+) operator.
list1 = [1, 2, 3,4]
list2 = [4, 5, 6]
joinedList = list1 + list2
print(joinedList)
Output:
[1, 2, 3, 4, 4, 5, 6]
Here, in the output you can see the duplicate items in the resulting list.
How to combining two lists and removing duplicates?
You can combining two lists in Python and removing duplicates could be accomplished by using a set() method.
list1 = [1, 2, 3,4]
list2 = [4, 5, 6]
joinedList = list(set(list1 + list2))
print(joinedList)
Output:
[1, 2, 3, 4, 5, 6]
Here, you can see the duplicate item 4 is removed from the resulting list.
Merge two lists in Python without duplicates

There is another method to remove duplicate items while merging two lists using set() method.
list1 = [1, 2, 3,4]
list2 = [4, 5, 6]
joinedList = list(set(list1) | set(list2))
print(joinedList)
Output:
[1, 2, 3, 4, 5, 6]
Other methods:
Using * operator to merge Two List in Python
The PEP, titled Additional Unpacking Generalizations, generally reduced some syntactic restrictions when using the starred * expression in Python. You can use star (*) operator to joining two lists (applies to any iterable).
list1 = [1, 2, 3]
list2 = [4, 5, 6]
joined_list = [*list1, *list2] # unpack both iterables in a list literal
print(joined_list)
Output:
[1, 2, 3, 4, 5, 6]
Using extend() to concatenate Two Lists in Python
Python List extend() method adds the specified list elements (or any iterable) to the end of the current list.
list1 = [1,2,3,4]
list2 = [4,5,6]
list1.extend(list2)
print(list1)
Output:
[1, 2, 3, 4, 5, 6]
Using List Comprehensions to add two lists in Python
Python List Comprehension offers a shorter syntax when you want to create a new list based on the values of an existing list.
list1 = [1, 2, 3,]
list2 = [4, 5, 6]
print([x for xs in [list1,list2] for x in xs])
Output:
[1, 2, 3, 4, 5, 6]
Using Python sum() to Join Multiple Lists in Python

list1 = [1, 2, 3,]
list2 = [4, 5, 6]
print(sum([list1, list2], []))
Output:
[1, 2, 3, 4, 5, 6]
Concatenation of many lists in Python
Python Itertools is used to iterate over data structures that can be stepped over using a for-loop. Such data structures are also known as iterables. Here, you can use Itertools.chain() function, that is used to chain multiple iterables together, by generating an iterator that traverses them sequentially, one after the other:
import itertools
list1 = [1, 2, 3]
list2 = ["one", "two", "three"]
list3 = ["a", "b", "c"]
joinedList = list(itertools.chain(list1,list2,list3))
print(joinedList)
Output:
[1, 2, 3, 'one', 'two', 'three', 'a', 'b', 'c']
Related Topics
- How to use Date and Time in Python
- Python Exception Handling
- How to Generate a Random Number in Python
- How to pause execution of program in Python
- How do I parse XML in Python?
- How to read and write a CSV files with Python
- Threads and Threading in Python
- Python Multithreaded Programming
- Python range() function
- How to Convert a Python String to int
- Python filter() Function
- Difference between range() and xrange() in Python
- How to print without newline in Python?
- How to remove spaces from a string in Python
- How to get the current time in Python
- Slicing in Python
- Create a nested directory without exception | Python
- How to measure time taken between lines of code in python?
- How to Find the Mode in a List Using Python
- Difference Between Static and Class Methods in Python?