How do i generate a tuple from a generator ?
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Fri May 15 21:38:47 EDT 2009
En Fri, 15 May 2009 17:58:55 -0300, eye zak <eye.zak.devel at gmail.com>
escribió:
> I have a situation where i want a tuple from a generator/sequence
> comprehension.
> I am wondering, is this possible ? or is this just a bad idea all
> together?
>
> class iterator(object):
> __slots__ = ('__iters',)
>
> def __init__(self,*args):
> assert len(args) != 0
> self.__iters = tuple( __builtins__.iter(arg) for arg in args )
>
> def __iter__(self,*args):
> return self
>
> def next(self):
> return [ i.next() for i in self.__iters ] # HERE I WANT A
> TUPLE
That is exactly what itertools.izip does
--
Gabriel Genellina
More information about the Python-list
mailing list