inverse of izip

Steven Bethard steven.bethard at
Thu Aug 19 23:10:05 CEST 2004

Peter Otten <__peter__ <at>> 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 starzip(iterables):
	def inner(itr, i):
		for t in itr:
			yield t[i]

	for i, itr in enumerate(itertools.tee(iterables)):
		yield inner(itr, i)

where i is now passed explicitly too.

Thanks again,


More information about the Python-list mailing list