How to concatenate multiple lists in Python

2 Answers

0 votes
list1 = [1, 2, 3, 4]
list2 = [5, 6, 7, 8]
list3 = [9, 10, 11, 12]

list4 = list1 + list2 + list3

print(list4)
 
 
 
'''
run:
 
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
 
'''

 



answered Apr 16, 2021 by avibootz
0 votes
import itertools

list1 = [1, 2, 3, 4]
list2 = [5, 6, 7, 8]
list3 = [9, 10, 11, 12]

list4 = list(itertools.chain(list1, list2, list3))


print(list4)
 
 
 
'''
run:
 
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
 
'''

 



answered Apr 16, 2021 by avibootz
...