c=[]
def dcc(dic):
for key in dic.keys():
print (key)
c.append(key)
vv=dic[key]
#判断下一级是否还是字典,如果是字典继续递归
if type(vv) == dict:
#print (len(dic[key]))
dcc(vv)
else:
print (vv)
print ('--------------')
print(c)
print(len(c))
def main():
test_dict = {'a':{'b':{'c':1,}}}
dcc(test_dict)
dd=main()
print('the depth of the dict is ',len(c))
a
b
c
1
--------------
['a', 'b', 'c']
3
the depth of the dict is 3