I propose to add a get_deep(*args, default=_sentinel) method to dict. It can accept a single argument, that must be an iterable, or multiple arguments.
The first element must be a key of the dict. If there's not a second element, the value is returned. If it's present, it tries to use it as an argument for the eventual __getitem__() of the value object, and so on. In this process, if a KeyError, an IndexError or a TypeError is raised, if default is set its value is returned, otherwise the exception will be raised. Example: d = {1: [42]} d.get_deep(1, 0) # 42 d.get_deep(range(3), default=1981) # 1981 d.get_deep((1, 1)) # IndexError: list index out of range _______________________________________________ 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/O53OTTDKWPQ7HZCODZSM7ZVNAQ5HVZG6/ Code of Conduct: http://python.org/psf/codeofconduct/