iterator wrapper
alf
ask at me
Sat Aug 12 09:18:14 EDT 2006
Paul Rubin wrote:
> alf <ask at me> writes:
>
>>>|>> I = ([n] for n in i)
>>
>>This is nice but I am iterating thru hude objects (like MBs) so you know ...
>
>
> I don't understand the objection-- the above is entirely correct and
> produces the same iterator you'd get from
>
> def wrap(i):
> for x in i:
> yield [x]
> I = wrap(i)
>
> You could also use
>
> import itertools
> I = itertools.imap(lambda x: [x], i)
>
> which again does the same thing.
I did see [] instead of () :-). this was a source of confusion.
okay, we have 3 functionally equal solution - which is most pythonic :-)
.... seroiusly ...
--
alf
More information about the Python-list
mailing list