python - Nested List of Lists to Single List of tuples -


i'm trying turn nested list of lists (number of lists can 2 lists +) single list of tuples.

the list looks this:

examplelist = [['a', 'b', 'c', 'd'], [1, 2, 3, 4], [10, 20, 30, 40]] 

and like this;

newlist = [('a', 1, 10), ('b', 2, 20), ('c', 3, '30)...] 

i know if zip(list1, list2), becomes list of tuple. how go doing list of lists?

i tried using zip concept with:

test = [] data in examplelist:      test.append(zip(data)) 

but did not work out me.

thanks in advanced help!

>>> examplelist = [['a', 'b', 'c', 'd'], [1, 2, 3, 4], [10, 20, 30, 40]] >>> list(zip(*examplelist)) [('a', 1, 10), ('b', 2, 20), ('c', 3, 30), ('d', 4, 40)] 

edit:

if want output list of lists, instead of list of tuples,

[list(i) in zip(*empamplelist)] 

should trick


Comments