Created
July 23, 2020 19:05
-
-
Save saintsGrad15/2a9c65dc6249b123029869cf700e79ed to your computer and use it in GitHub Desktop.
A tail-recursive function to return the value at a path within a dictionary.
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
| def get_dict_path(dict_, path, default=None): | |
| if len(path) < 1: | |
| return dict_ | |
| return get_dict_path(dict_.get(path[0], default), path[1:], default) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment