Created
July 3, 2018 05:56
-
-
Save jaforsgren/663996ea111084b056c687d9137df957 to your computer and use it in GitHub Desktop.
get key/value from nested dict
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 getKeyValues(dictionary, key, entryList=[]): | |
pList = [] | |
for entry in dictionary: | |
if isinstance(dictionary[entry],list): | |
for i in dictionary[entry]: | |
pList += getKeyValues(i,key) | |
else: | |
if isinstance(dictionary[entry],list): | |
pList += getKeyValues(dictionary[entry],key) | |
if isinstance(dictionary[entry],dict): | |
pList += getKeyValues(dictionary[entry],key) | |
if entry.lower() == key: | |
pList.append({entry:dictionary[entry]}) | |
entryList = pList | |
return entryList | |
print getKeyValues(d,"id") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment