Created
July 15, 2015 02:51
-
-
Save stenius/26d0b1523ea7980b3745 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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