统计字典或者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
原文地址:https://www.cnblogs.com/come202011/p/12732391.html