Created
August 29, 2012 18:55
-
-
Save pythonjunkie/3517111 to your computer and use it in GitHub Desktop.
Extracting key value pairs from a dictionary
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 extract(dictin): | |
dictout={} | |
for key, value in dictin.iteritems(): | |
print('key:%s \t Value:%s' % (key,value)) | |
if isinstance(value, dict): | |
extract(value, dictout) | |
elif isinstance(value, list): | |
for i in value: | |
extract(i,dictout) | |
else: | |
dictout[key] = value | |
print('Dictout:%s' % dictout) | |
return dictout |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment