Examples of how to merge two lists in python:
Merging two lists in python using the + operator
>>> l1 = [1,2,3]>>> l2 = [4,5,6]>>> l3 = l1 + l2>>> l3[1, 2, 3, 4, 5, 6]
another example:
>>> l1 = [1,2,3]>>> l2 = [4,5,6]>>> l3 = l2 + l1>>> l3[4, 5, 6, 1, 2, 3]
Combining two lists using zip
If the goal is to iterate over two lists, a solution is to use zip, example
>>> l1 = ['a','b','c']>>> l2 = [1,2,3]>>> for x,y in zip(l1,l2):... print(x,y)...a 1b 2c 3
References
| Links | Site |
|---|---|
| How to append list to second list (concatenate lists) | stackoverflow |
| How to merge multiple lists into one list in python? [duplicate] | stackoverflow |
