This sounds to me like functionality of a specific type (more specific than 
`dict`). `dict` can have any key-value pairs, it is not necessarily a nested 
structure of dicts. Thus having a method for such a specific use case with the 
general dict type doesn't feel right.

I think it's better if such functionality is provided by whatever 
infrastructure creates those specific data structures (the nested dicts). For 
example there is this project: [pyhocon](https://github.com/chimpler/pyhocon/) 
, a HOCON parser for Python which supports exactly that syntax:

    conf['databases.mysql.host']  # conf is a nested dict of depth 3

Also writing a custom function isn't too much work:

    def dig(d, *keys, default=None):
        obj = d.get(keys[0], default)
        if len(keys) > 1:
            return dig(obj, *keys[1:], default=default) if isinstance(obj, 
dict) else default
        return obj
_______________________________________________
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/Q3Z4STN4VMNMKGMWB37WL3BLHETEKRDI/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to