How do I not make a list?

Neil Cerutti horpner at yahoo.com
Thu Nov 29 08:29:05 EST 2007


On 2007-11-29, Just Another Victim of the Ambient Morality
<ihatespam at hotmail.com> wrote:
> It may sound like a strange question but that's probably only
> because I don't know the proper terminology.  I have an
> iterable object, like a list, and I want to perform a transform
> on it (do an operation on each of the elements) and then pass
> it onto something else that expects and iterable. I'm pretty
> sure this something else doesn't need a list, either, and just
> wants to iterate over elements.

Try itertools.imap.

 something_else(imap(do_operation, an_iterable))

-- 
Neil Cerutti
You've got to take the sour with the bitter. --Samuel Goldwyn



More information about the Python-list mailing list