How to make a list of tuples from several lists?

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

Answers (3)

HK boy
HK boy

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

dwarvenharem
dwarvenharem

Reputation: 43

You can do it like so:

list(zip(a, b, c))

Upvotes: 1

shaik moeed
shaik moeed

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

Related Questions