Created
September 10, 2019 14:37
-
-
Save johnberroa/8e6d383b5f8d449010fff6a2f294af90 to your computer and use it in GitHub Desktop.
Dive into a dictionary given a key path separated by "/"
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 dive_into_dict(path, dic): | |
path = path.split("/") | |
key = path[0] | |
result = dic[key] | |
if isinstance(result, dict): | |
result = dive_into_dict("/".join(path[1:]), result) | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment