Skip to content

Instantly share code, notes, and snippets.

@commanda
Created July 27, 2016 15:48
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 commanda/ba415b1852f9ba7e0f4403f9d4e7df7d to your computer and use it in GitHub Desktop.
Save commanda/ba415b1852f9ba7e0f4403f9d4e7df7d to your computer and use it in GitHub Desktop.
traverse a json-esque structure in python
def value_generator(data):
if isinstance(data, dict):
for key, value in data.iteritems():
for element in value_generator(value):
yield element
elif isinstance(data, list):
for sublist in data:
for element in value_generator(sublist):
yield element
else:
yield data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment