Created
July 27, 2016 15:48
-
-
Save commanda/ba415b1852f9ba7e0f4403f9d4e7df7d to your computer and use it in GitHub Desktop.
traverse a json-esque structure in python
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 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