Supposing we have this dict:
d = {\'a\':1, \'b\': {\'c\':{}}}
What would be the most straightforward way of knowing the nesting depth>
A non-recursive solution:
def depth(d): depth=0 q = [(i, depth+1) for i in d.values() if isinstance(i, dict)] max_depth = 0 while (q): n, depth = q.pop() max_depth = max(max_depth, depth) q = q + [(i, depth+1) for i in n.values() if isinstance(i, dict)] print max_depth