In this python dictionary program, we will get the depth of the dictionary.
Steps to solve the program
D1 = {'a':1,'b':{'c':{'d':{}}}}
def depth(d):
if isinstance(d, dict):
return 1 + (max(map(depth, d.values())) if d else 0)
return 0
print(depth(D1))
Output :
4