How do I not make a list?

Just Another Victim of the Ambient Morality ihatespam at hotmail.com
Thu Nov 29 03:26:26 EST 2007


    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.
    Now, I could just make a list, using a list comprehension, performing my 
operation on each element, and then pass that list on, knowing that it is 
iterable.  However, I was wondering if there was a way I can do virtually 
this without having to actually allocate the memory for a list.  Creating a 
stock iterator or generator or whatever it's called, with a passed in 
operation?
    I hope I've described this adequately.
    Thank you...






More information about the Python-list mailing list