-
-
Save yellowbean/af06a67bb1c4a94b9ed30d667ca68480 to your computer and use it in GitHub Desktop.
query nested python map structured
This file contains hidden or 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
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