how can this iterator be optimized?
Terry Reedy
tjreedy at udel.edu
Thu Feb 12 00:41:39 EST 2009
Basilisk96 wrote:
>> Don't use a generator then. If you're going to finally return a list (and
>> sorted does exactly that), build a list right from the start:
>
> Good point. However, for the sake of argument, what if I removed the
> sorting requirement and simply wanted the generator?
Write a generator function with the same loop and a yield.
? I usually strive
> for comprehensions if a for loop can be reduced to such.
You are overdoing it, I think. Generator expressions are for saving
programmer time, not machine time.
More information about the Python-list
mailing list