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


How to Merge Two Lists into One in Python
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


How To Concatenate 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']