Reputation: 25
I have 3 lists:
a = [0, 1, 2]
b = [3, 4, 5]
c = [6, 7, 8]
And I need to create a list of tuples from them.
The output should look like this:
[(0, 3, 6), (1, 4, 7), (2, 5, 8)]
Upvotes: 0
Views: 92
Reputation: 1406
Just using zip
only.
a = [0, 1, 2]
b = [3, 4, 5]
c = [6, 7, 8]
zipped = list(zip(a, b, c))
Upvotes: 3
Reputation: 5785
Try this,
>>> a,b,c =[0, 1, 2],[3, 4, 5],[6, 7, 8]
>>> [(i,j,k) for i,j,k in zip(a,b,c)]
[(0, 3, 6), (1, 4, 7), (2, 5, 8)]
Upvotes: 2