Created
January 11, 2018 19:28
-
-
Save nod/54cbcd53560190a7b52dd3148ceb4d43 to your computer and use it in GitHub Desktop.
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
>>> sample = {"a":2,"b":{"c":44}} | |
>>> sample.get("b",{}).get("c") # is gross | |
>>> | |
>>> class nestdict(dict): | |
... def __floordiv__(self, k): | |
... v = self.get(k) | |
... if isinstance(v, dict): return nestdict(v) | |
... return v | |
... | |
>>> z = nestdict(sample) | |
>>> z // "a" | |
2 | |
>>> z // "b" | |
{'c': 44} | |
>>> z // "b" // "c" | |
44 | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment