Last active
October 9, 2015 13:23
-
-
Save dusan87/2a50380cd6058535099f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def depth(dictionary, count=0): | |
count +=1 | |
# I use sorted for our case | |
# to print out as it's expected in the written task | |
# We should use OrderDict as input if it's required to keep the order of dict. | |
for key, value in sorted(dictionary.items()): | |
print key, count | |
if isinstance(value, dict): | |
depth(value, count) | |
if __name__ == "__main__": | |
a = {"key1":1, | |
"key2": { | |
"key3": 1, | |
"key4": { | |
"key5":1, | |
} | |
} | |
} | |
depth(a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment