Thanks for the suggestion! I agree that using a list is clearer that having a trailing comma, I like it!

I still think that having a one() function would be useful, since:
1. I think it spells the intention more clearly. Also the exception would be easier to understand, since errors in tuple unpacking usually mean something else.
2. The one() function allows you to use the result inside an expression without assigning it to a variable.

Cheers,
Noam

On Mon, Jul 27, 2020 at 10:30 PM Chris Angelico <rosuav@gmail.com> wrote:
On Tue, Jul 28, 2020 at 5:24 AM Steven Barker <blckknght@gmail.com> wrote:
>
> A single-name unpacking assignment can do exactly what you want, albeit with slightly less helpful exception messages:
>
>     jack, = (p for p in people if p.id == '1234') # note comma after the name jack
>

Agreed. As a minor readability refinement, I would prefer to spell
this with square brackets:

[jack] = (p for p in people if p.id == '1234')

The effect is identical, but for the one-item unpack, I prefer not to
have the vital-but-subtle trailing comma.

(You can use square brackets on larger assignment lists too, but they
don't add anything.)

ChrisA
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/62ZAKSHT6VHT66CHFBPJHHAUQSW2S3DK/
Code of Conduct: http://python.org/psf/codeofconduct/