Monday, 31 July 2017

How do I concatenate two lists in Python?



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



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]

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...