On 20 November 2014 22:54, MRAB <python@mrabarnett.plus.com> wrote:
I'd prefer 'while' instead:
[x for x in range(10) while x < 5] [0, 1, 2, 3, 4] {x for x in range(10) while x < 5} {0, 1, 2, 3, 4} {x:x for x in range(10) while x < 5} {0:0, 1:1, 2:2, 3:3, 4:4}
That's been suggested many times, and always fails on the grounds of being completely incompatible with the expansions of comprehensions and generator expressions as nested compound statements. The return expression idea is one that reflects the actual deep structure of the nested scopes that underlie the syntactic sugar, so it's compatible with the expansion. This idea was mainly aimed at folks that might be inclined to worry about the possible loss of the "or stop()" generator expression trick in PEP 479, though. If that trick wasn't currently possible, and wasn't being proposed for removal, I never would have posted this idea. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia