Skip to content

Instantly share code, notes, and snippets.

@stenius
Created July 15, 2015 02:51
Show Gist options
  • Save stenius/26d0b1523ea7980b3745 to your computer and use it in GitHub Desktop.
Save stenius/26d0b1523ea7980b3745 to your computer and use it in GitHub Desktop.
# check depth of keys
#
a = {
'key1': 1,
'key2': {
'key3': 1,
'key4': {
'key5': 4
}
}
}
def print_depth(data, depth=0, key=''):
'''print key and depth'''
try:
data.keys()
except:
print key, depth
return depth
if key:
print key, depth
return [print_depth(data[k], depth+1, k) for k,v in data.iteritems()]
print_depth(a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment