>>> def count(d): >>> return max(count(v) if isinstance(v,dict) else 0 for v in d.values()) + 1 参考:https://stackoverflow.com/a/43587619