Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine two lists into one multidimensional list

Tags:

python

list

I would like to merge two lists into one 2d list.

list1=["Peter", "Mark", "John"]
list2=[1,2,3]

into

list3=[["Peter",1],["Mark",2],["John",3]]
like image 457
ogward Avatar asked Mar 21 '26 21:03

ogward


1 Answers

list3 = [list(a) for a in zip(list1, list2)]
like image 103
eumiro Avatar answered Mar 23 '26 11:03

eumiro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!