inverse of izip
steven.bethard at gmail.com
Thu Aug 19 23:10:05 CEST 2004
Peter Otten <__peter__ <at> web.de> writes:
> You can model the nested generator expressions' behaviour with the following
> function - which I think is much clearer.
> def starzip(iterables):
> def inner(itr):
> for t in itr:
> yield t[i]
> for (i, itr) in enumerate(it.tee(iterables)):
> yield inner(itr)
> Note how itr is passed explicitly, i. e. it is not affected by later
> rebindings in startzip() whereas i is looked up in inner()'s surrounding
> namespace at every yield.
Thanks, that was really helpful! It also clarifies why your solution works
right; your code basically does:
def inner(itr, i):
for t in itr:
for i, itr in enumerate(itertools.tee(iterables)):
yield inner(itr, i)
where i is now passed explicitly too.
More information about the Python-list