Created
April 7, 2015 19:57
-
-
Save prasincs/1ebf4b706f587571682f to your computer and use it in GitHub Desktop.
clojurey-python
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
UNKNOWN = "" | |
def get_in(d, key, no_key_value): | |
if type(d) != dict: | |
return d | |
else: | |
if key[0] in d: | |
return get_in(d[key[0]], key[1:], no_key_value) | |
else: | |
return no_key_value | |
test_dict={"a": 1, "b": {"c": 2}} | |
assert(get_in(test_dict, ["a"], UNKNOWN) == 1) | |
assert(get_in(test_dict, ["b", "c"], UNKNOWN) == 2) | |
assert(get_in(test_dict, ["b", "d"], UNKNOWN) == UNKNOWN) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment