统计字典或者json字符串最大深度

 

# 统计字典或者json字符串的深度


def depth(x):
    if type(x) is dict and x:
        return 1 + max(depth(x[a]) for a in x)
    if type(x) is list and x:
        return 1 + max(depth(a) for a in x)
    return 0

 

posted on 2020-04-19 17:19  芦荟~lh  阅读(397)  评论(0编辑  收藏  举报

导航