How do I make a generator from two lists in python? -
give lists a, b
a = [5, 8, 9] b = [6, 1, 0]
i want create generator gen such that:
for x in gen: print x
outputs
5, 8, 9, 6, 1, 0
you use itertools.chain
:
>>> itertools import chain >>> = [5, 8, 9] >>> b = [6, 1, 0] >>> it=chain(a,b) >>> x in it: print x, ... 5 8 9 6 1 0
Comments
Post a Comment