You were almost there. In Python 3, just pass the generators to zip()
:
for a, b in zip(A(), B()):
zip()
takes any iterable, not just lists. It will consume the generators one by one.
In Python 2, use itertools.izip()
:
from itertools import izip
for a, b in izip(A(), B()):
As an aside, turning a generator into a list is as simple as list(generator)
; no need to use a list comprehension there.