-
-
Save mybigman/218e6db90c6280c37f2100f7a4aa7590 to your computer and use it in GitHub Desktop.
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
>>> 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