On Sat, Feb 6, 2021 at 5:21 PM Random832 <[email protected]> wrote:
>
> While we're on the subject of assignment expression limitations, I've 
> occasionally wanted to write something like
>
> try:
>     return a_dict[key]
> except KeyError:
>     return (a_dict[key] := expression to construct value)

That's what the __missing__ method is for.

ChrisA
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/L4ONADSKEO5WBHREGU6LAHWFOS7DC5EI/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to