Skip to content

Instantly share code, notes, and snippets.

@jaforsgren
Created July 3, 2018 05:56
Show Gist options
  • Save jaforsgren/663996ea111084b056c687d9137df957 to your computer and use it in GitHub Desktop.
Save jaforsgren/663996ea111084b056c687d9137df957 to your computer and use it in GitHub Desktop.
get key/value from nested dict
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