[Solved] How to combine lists? (Python) [duplicate]


Just use zip to get tuples of values at corresponding indices in the two lists, and then cast each tuple to a list. So:

[list(t) for t in zip(list1, list2)]

is all you need to do.

Demo:

>>> list1 = ["X", "Y", "Z"]
>>> list2 = [1, 2, 3]
>>> list3 = [list(t) for t in zip(list1, list2)]
>>> list3
[[1, 'X'], [2, 'Y'], [3, 'Z']]

solved How to combine lists? (Python) [duplicate]