Paul Rubin wrote:
python at rcn.com (Raymond Hettinger) writes:
In brief, the PEP proposes a list comprehension style syntax for
creating fast, memory efficient generator expressions on the fly:

sum(x*x for x in roots)

This is a little confusing. Consider:

1) [x*x for x in roots]
2) (x*x for x in roots)

#2 looks like it should be a "sequence comprehension" and not a
generator expression. I'd go back to your earlier proposal of
using a yield keyword if you want a generator expression:

sum(yield x for x in roots)
I too prefer the above use of yield because then you can always
associate generators with the yield keyword.


Search Discussions

Discussion Posts


Follow ups

Related Discussions



site design / logo © 2022 Grokbase