[Python-ideas] Inline assignments using "given" clauses

MRAB python at mrabarnett.plus.com
Tue May 15 13:10:56 EDT 2018


On 2018-05-15 04:32, Tim Peters wrote:
> Just noting some real code I typed today where `given` works great if
> it allows unpacking syntax, and assignment expressions don't:
> 
>      while True:
>          head, matched, s = s.partition(sep)
>          if not matched:
>              break
> 
> Using `given`:
> 
>       while matched given head, matched, s = s.partition(sep):
> 
> Typing "matched " twice still sucks, though;-)
> 
[snip]

If you're using .partition multiple times, you might as well use .split 
instead!


More information about the Python-ideas mailing list