How do I concatenate two lists in Python?

y2k picture y2k · Nov 12, 2009 · Viewed 2.8M times · Source

How do I concatenate two lists in Python?

Example:

listone = [1, 2, 3]
listtwo = [4, 5, 6]

Expected outcome:

>>> joinedlist
[1, 2, 3, 4, 5, 6]

Answer

Daniel G picture Daniel G · Nov 12, 2009

You can use the + operator to combine them:

listone = [1,2,3]
listtwo = [4,5,6]

joinedlist = listone + listtwo

Output:

>>> joinedlist
[1,2,3,4,5,6]