[Python-ideas] Map-then-filter in comprehensions

Pavol Lisy pavol.lisy at gmail.com
Fri Mar 11 07:08:46 EST 2016


2016-03-11 6:38 GMT+01:00, Franklin? Lee <leewangzhong+python at gmail.com>:
> On Mar 10, 2016 10:51 PM, "Nick Coghlan" <ncoghlan at gmail.com> wrote:
>>
[...]

>> It's also worth reading PEP 343 for Guido's explanation for why the
>> context management assignment syntax isn't "with VAR = EXPR": it's
>> because EXPR *isn't* the thing being assigned, but rather a stepping
>> stone towards obtaining that thing. This characteristic is true of all
>> of the places where "as" is currently used instead of "=":
[...]
> Then would it be a problem if it defaulted to the value of EXPR directly
> when that value isn't of a specially-handled type (such as a context
> manager, for `with`)? Other than that learning `with` in comprehensions
> might make it harder to learn context managers.

Or we could think about syntax "with VAR = EXPR" where it is plain assignment.

If we wanted in PEP343 (and still we want) to have different syntax
for different semantics then it is better, I think.

PS. from my point of view I still don't see why is "with" so much
better than existing syntax "for VAR in [EXPR]"

for example why is this not enough? ->

import unicodedata
[(c, i, cat, name, norm) for i in range(1, 0x110000)
    for c in [chr(i)]
    for cat in [unicodedata.category(chr(i))]
    for name in [unicodedata.name(chr(i), 'noname')]
    for uname in [name.upper()]                                     #
name is defined in previous row
    for norm in [unicodedata.normalize('NFKC', chr(i))]
  if 'OPERATOR' in uname
  if norm != c
]

PPS. if we want to change syntax the "for VAR = EXPR" is also possibility


More information about the Python-ideas mailing list