本文主要是介绍Python - Get leaves count in a dictionary,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
def get_dict_leaves_count(dic):
if len(dic) == 0:
return 0
else:
cnt = 0
for k, v in dic.items():
if not isinstance(v, Mapping):
cnt += 1
else:
cnt += get_dict_leaves_count(v)
return cnt
这篇关于Python - Get leaves count in a dictionary的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!