[Python-Dev] PEP 289 - Generator Expressions - Let's Move Forward
Samuele Pedroni
pedronis at bluewin.ch
Fri Apr 30 08:48:06 EDT 2004
At 05:16 30.04.2004 -0700, Guido van Rossum wrote:
>A more general question would be: have you found any examples of list
>comprehensions that weren't immediately used where there would be a
>compelling reason to use a generator expression instead? In this
>example, I can't see any of the touted advantages -- the set of
>command line options will never be long enough to have to worry about
>the memory consumption. How about the other examples you found?
this assumes that people will choose either generator expressions or list
comprehesions on a case-by-case basis. I'm not sure it's a reasonable
assumption for the whole range of users - starting with newbies. Probably
documentation and what is predicated on c.l.p will influence this.
OTOH both are probably good enough default choices, list comprehesions
because if one gets insufficient performance she will learn to switch,
generator expressions because for small numbers of elements things are a
wash (unless someone is cretating a lot of small sequences :)).So the more
they are interchangeable in all other respects the better.
"There should be one-- and preferably only one --obvious way to do it."
of course this is the case for generator expressions and list
comprehsensions because they are separated
by performance characteristics and somehow by the fact that one directly
produces a list. I suspect that we have to learn to live with the fact that
they are distinguished by (just) that, both a nuisance (sometimes people
don't want to bother to choose) and a feature.
regards.
More information about the Python-Dev
mailing list