Re: [Python-Dev] The new and improved PEP 572, same great taste with 75% less complexity!

2018年4月25日 16:32:26 -0700

> # Handle a matched regex
> if (match := pattern.search(data)) is not None:
> ...
>
> # A more explicit alternative to the 2-arg form of iter() invocation
> while (value := read_next_item()) is not None:
> ...
>
> # Share a subexpression between a comprehension filter clause and its 
> output
> filtered_data = [y for x in data if (y := f(x)) is not None]
What do you think of adding the variant without the new ":=" syntax?
It would help to see the benefit of the new ":=" syntax, and help to
compare the two syntaxes.
if:
 if (match := pattern.search(data)) is not None: ...
vs
 match = pattern.search(data)
 if match is not None: ...
while:
 while (value := read_next_item()) is not None: ...
vs
 while True:
 value = read_next_item()
 if value is None: break
 ...
list-comprehension:
 filtered_data = [y for x in data if (y := f(x)) is not None]
vs
 filtered_data = [f(x) for x in data]
 filtered_data = [x for x in filtered_data if x is not None]
Victor
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to