Last active
December 12, 2015 08:08
-
-
Save diopib/4741846 to your computer and use it in GitHub Desktop.
Python Nested Dictionaries Traversal Search
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
def df_traversal(d): | |
""" | |
depth-first traversal for dict d | |
pre-order method | |
ref: http://en.wikipedia.org/wiki/Tree_traversal | |
ref: http://en.wikipedia.org/wiki/Depth-first_search | |
""" | |
for key in d: | |
print key | |
if type(d[key]) == dict: | |
df_traversal(d[key]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment