In this article, I’ll show you 7 different ways to combine lists in Python. I’m sure, there could be many more, but I found these ones the most frequently used ones.
Way 1: Using Extend
Python
list1 = [1,2,3]
list2 = [4,5]
list1.extend(list2)
print(list1)
#output ==> [1,2,3,4,5]Way 2: Using +
Python
list1 = [1,2,3]
list2 = [4,5]
list3 = list1 + list2
print(list3)
#output ==> [1,2,3,4,5]Way 3: Using Sum(…)
Python
list1 = [[1,2,3],[4,5]]
list2 = sum(list1,[])
print(list2)
#output ==> [1,2,3,4,5]Way 4: Using Append(…)
Python
list1 = [1,2,3]
list2 = [4,5]
for l in list2:
list1.append(l)
print(list1)
#output ==> [1,2,3,4,5]Way 5: Using List Comprehension
Python
list1 = [[1,2,3], [4,5]]
list2 = [item for childList in list1 for item in childList]
print(list2)
#output ==> [1,2,3,4,5]Way 6: Using Itertools
Python
import itertools
list1 = [[1,2,3], [4,5]]
list2 = list(itertools.chain.from_iterable(list1))
print(list2)
#output ==> [1,2,3,4,5]Way 7: Using *
Python
list1 = [1,2,3]
list2 = [4,5]
list3 = [*list1, *list2]
print(list3)
#output ==> [1,2,3,4,5]Hope you enjoyed reading this article and learned at least one new way to combine lists.
Do not forget to check out my video portraying all of these ways here.


Koshila SenadhiraPosted Dec 1, 2022, 6:20 AM EST
Interesting Article!
Abhishek YadavPosted Oct 19, 2022, 4:27 AM EDT
Helpful article thanks for posting this