Skip to content

Instantly share code, notes, and snippets.

@yellowbean
Created October 24, 2022 05:07
Show Gist options
  • Save yellowbean/af06a67bb1c4a94b9ed30d667ca68480 to your computer and use it in GitHub Desktop.
Save yellowbean/af06a67bb1c4a94b9ed30d667ca68480 to your computer and use it in GitHub Desktop.
query nested python map structured
stuff = {
"A":{
"B":{
"C":"D"
}
}
}
def query(d,p):
if len(p)==1:
return d[p[0]]
else:
return query(d[p[0]],p[1:])
query(stuff,["A","B","C"])
# "D"
query(stuff,["A","B"])
# {"C":"D"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment