7 Ways To Combine Lists In Python
2 min readAug 29, 2022
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
list1 = [1,2,3]list2 = [4,5]list1.extend(list2)print(list1) #output ==> [1,2,3,4,5]
Way 2: Using +
list1 = [1,2,3]list2 = [4,5]list3 = list1 + list2print(list3)
Way 3: Using Sum(…)
list1 = [[1,2,3],[4,5]]list2 = sum(list1,[])print(list2)
Way 4: Using Append(…)
list1 = [1,2,3]list2 = [4,5]for l in list2:list1.append(l)