Skip to content

Instantly share code, notes, and snippets.

@prasincs
Created April 7, 2015 19:57
Show Gist options
  • Save prasincs/1ebf4b706f587571682f to your computer and use it in GitHub Desktop.
Save prasincs/1ebf4b706f587571682f to your computer and use it in GitHub Desktop.
clojurey-python
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