On Sat, Feb 6, 2021 at 5:21 PM Random832 <random...@fastmail.com> 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 -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/L4ONADSKEO5WBHREGU6LAHWFOS7DC5EI/ Code of Conduct: http://python.org/psf/codeofconduct/