I have 3 lists examples below, I want to match each one and create new lists
l1 = [a,b,c]
l2= [1,2,3]
l3=[7,8,9]
How do I create 3 new lists with expected output:
l1 = [a,1,7]
l2= [b,2,8]
l3=[c,3,9]
Thanks!
I have 3 lists examples below, I want to match each one and create new lists
l1 = [a,b,c]
l2= [1,2,3]
l3=[7,8,9]
How do I create 3 new lists with expected output:
l1 = [a,1,7]
l2= [b,2,8]
l3=[c,3,9]
Thanks!
Use zip
or a comprehension:
# Create a list of lists
ls = [l1, l2, l3]
ls = list(zip(*ls)) # output: a list of tuples
# OR
ls = [l for l in zip(*ls)] # output: a list of lists
Output:
>>> ls[0]
['a', 1, 7]
>>> ls[1]
['b', 2, 8]
>>> ls[2]
['c', 3, 9]