Skip to content

Instantly share code, notes, and snippets.

@diopib
Last active December 12, 2015 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diopib/4741846 to your computer and use it in GitHub Desktop.
Save diopib/4741846 to your computer and use it in GitHub Desktop.
Python Nested Dictionaries Traversal Search
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