python - Iterate over a tuple of lists -
this question has answer here:
i have tuple of lists. each list in tuple has same number of elements. how can iterate on in loop
ex:
tuplelist = ([1,2,3], ['label1', 'label2', 'label3']) (val, label) in <something>: print val, label
should output:
1, label1 2, label2 3, label3
note: list of tuples contain more 2 lists.
ps: have opted duplicate, please check responses correct solution. it's different iterating through 2 separate lists.
you can use zip , flatten tuple_list asterix syntax.
tuple_list = ([1,2,3], ['label1', 'label2', 'label3']) val, label in zip(*tuple_list): print(val, label)
if you're still in python 2.7:
import itertools tuple_list = ([1,2,3], ['label1', 'label2', 'label3']) val, label in itertools.izip(*tuple_list): print val, label
Comments
Post a Comment