How do I concatenate two lists in Python?
Example:
JavaScript
x
3
1
listone = [1, 2, 3]
2
listtwo = [4, 5, 6]
3
Expected outcome:
JavaScript
1
3
1
>>> joinedlist
2
[1, 2, 3, 4, 5, 6]
3
Advertisement
Answer
Use the +
operator to combine the lists:
JavaScript
1
5
1
listone = [1, 2, 3]
2
listtwo = [4, 5, 6]
3
4
joinedlist = listone + listtwo
5
Output:
JavaScript
1
3
1
>>> joinedlist
2
[1, 2, 3, 4, 5, 6]
3