generator expressions: performance anomaly?

Diez B. Roggisch deetsNOSPAM at web.de
Tue Jan 18 09:08:44 EST 2005


> My thoughts where to let the 'leftmost' section of the expression to be
> intact so that any of the dynamic things done to this part, i.e.
> replacing time.time with random.random are taken into consideration.
> What can be done is to extract the expression into a loopless structure
> 
> lst = list(time.time() for i in xrange(10))
> would be compiled to the bytecode version of:
> lst = [time.time(), time.time(), time.time(), time.time() ...]
> 
> Then time.time can do whatever it wants to. It's the (x)range function
> that we need to enshure returns the same values in every execution. This
> *IS* a useless feature, but I think it's possible to make it work.

What makes the leftmost expression different from the iterable returning
expression inside the for? The same arguments apply there.

-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list