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
If no value is yielded by the generator expression, you'll get "ValueError:
not enough values to unpack (expected 1, got 0)". If multiple values are
yielded, you'll instead get "ValueError: too many values to unpack
(expected 1)".
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/Y6HFE3HIPX67UCFSLO6WMH4CKVAEJYJO/
Code of Conduct: http://python.org/psf/codeofconduct/