[Python-Dev] PEP 289 - Generator Expressions (original) (raw)

[Python-Dev] PEP 289 - Generator Expressions - Let's Move Forward

Edward Loper edloper at gradient.cis.upenn.edu
Fri Apr 30 12:29:04 EDT 2004


Hello Guido,

I did a quick review of the stdlib, including the tests, to see which list comprehensions could be replaced with generator expressions. Thought I admit I am biased towards early binding, I ended up looking for cases with the following properties: [...]

Even if we switched to early binding, won't these issues still bite you with mutable values? E.g.:

 some_dict = {'x': 1, 'y': 2}
 iter1 = (some_dict.get(v, 3) for v in input1)
 some_dict['z'] = 5
 iter2 = (some_dict.get(v, 7) for v in input2)

It seems like it would be surprising (to me, anyway) if this gave a different result than:

 some_dict = {'x': 1, 'y': 2}
 iter1 = (some_dict.get(v, 3) for v in input1)
 some_dict = {'x': 1, 'y': 2, 'z': 5}
 iter2 = (some_dict.get(v, 7) for v in input2)

-Edward



More information about the Python-Dev mailing list