You need to create a recursive function:
>>> def depth(d):
... if isinstance(d, dict):
... return 1 + (max(map(depth, d.values())) if d else 0)
... return 0
...
>>> d = {'a':1, 'b': {'c':{}}}
>>> depth(d)
3
More Related Contents:
- Using lambda function in python
- Make a dictionary with duplicate keys in Python
- Access a particular field in arbitrarily nested JSON data [duplicate]
- How to implement an ordered, default dict?
- Why do my Tkinter widgets get stored as None? [duplicate]
- How can you print a variable name in python? [duplicate]
- Multi-level defaultdict with variable depth?
- Python: Maximum recursion depth exceeded
- Python dictionary from an object’s fields
- Why can a Python dict have multiple keys with the same hash?
- TypeError: ‘dict’ object is not callable
- List of tuples to dictionary [duplicate]
- [] and {} vs list() and dict(), which is better?
- python tuple to dict
- One liner: creating a dictionary from list with indices as keys
- Can PyYAML dump dict items in non-alphabetical order?
- Group by multiple keys and summarize/average values of a list of dictionaries
- Object-like attribute access for nested dictionary
- Override the {…} notation so i get an OrderedDict() instead of a dict()?
- Creating a tree/deeply nested dict from an indented text file in python
- Changing marker style in scatter plot according to third variable
- Why does this python dictionary get created out of order using setdefault()?
- Checking a nested dictionary using a dot notation string “a.b.c.d.e”, automatically create missing levels
- How to create a Python dictionary with double quotes as default quote format?
- Python – Printing a dictionary as a horizontal table with headers
- How to completely traverse a complex dictionary of unknown depth?
- How to set default value to all keys of a dict object in python?
- Python: is “except KeyError” faster than “if key in dict”?
- How do I merge dictionaries together in Python?
- Python: Writing Nested Dictionary to CSV