I have list1, list2 and list3 and I wnat to merge them to a single array without changing their key
I checked stackoverflow and python.org
list1 =[1,2,3]
list2=[4,5,6]
list3=[7,8,9]
final_expected_result =[[1,4,7],[4,5,8],[3,6,9]]
I have list1, list2 and list3 and I wnat to merge them to a single array without changing their key
I checked stackoverflow and python.org
list1 =[1,2,3]
list2=[4,5,6]
list3=[7,8,9]
final_expected_result =[[1,4,7],[4,5,8],[3,6,9]]
I think that zip
is what you're looking for. zip
does return an iterable object, so you'll likely want to convert it to a list.
>>> list(zip(list1, list2, list3))
[(1, 4, 7), (2, 5, 8), (3, 6, 9)]
If you're set on having a list of lists instead of a list of tuples integrate a map
into the expression.
>>> list(map(list, zip(list1, list2, list3)))
[[1, 4, 7], [2, 5, 8], [3, 6, 9]]