[Tim]
>> 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]

[MRAB <pyt...@mrabarnett.plus.com>]
> If you're using .partition multiple times, you might as well use .split
> instead!

Possibly - depends on what the rest of the loop is doing.  In this
specific case, there are paths in the loop body that change what `sep`
is bound to, so I'd have to pass `maxsplit=1` to get a clumsier way to
do what `partition()` does directly,  For example,

>>> "a+b".split("+", maxsplit=1) # separator wholly contained
['a', 'b']
>>> "a-b".split("+", maxsplit=1) # separator doesn't appear at all
['a-b']

I'ts more convenient that `partition()` always returns a 3-tuple, not
sometimes a 1-list and other times a 2-list.
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to