dict.get_deep()

Dieter Maurer dieter at handshake.de
Sun Apr 3 17:53:34 EDT 2022


Marco Sulla wrote at 2022-4-3 21:17 +0200:
>On Sun, 3 Apr 2022 at 18:57, Dieter Maurer <dieter at handshake.de> wrote:
>> You know you can easily implement this yourself -- in your own
>> `dict` subclass.
>
>Well, of course, but the question is if such a method is worth to be
>builtin, in a world imbued with JSON. I suppose your answer is no.
```
def mget(m, *keys):
  """return m[k1][k2]...[kn] or `None`"""
  for k in keys():
    if k not in m: return
    m = m[k]
  return m
```
Thus, it is so simple to get what you want.
No need to make it builtin.

--
Dieter


More information about the Python-list mailing list