Python how to iterate two infinite generators at the same time? -
i'd iterate on number of infinite generators:
def x(y): while true: in xrange(y): yield i,j in zip(x(5),x(3)): print i,j
the code above will produce nothing. doing wrong?
that's because python 2 zip
tries create list getting elements generator ever produce. want iterator, i.e. itertools.izip
.
in python 3 zip
works izip
.
Comments
Post a Comment