Last active
January 8, 2021 09:09
-
-
Save onelharrison/b3c89cc4bdda9d44db07e0aa8cc3c330 to your computer and use it in GitHub Desktop.
Implementation of a dig function in Python
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
from functools import reduce | |
def dig(collection, *keys, default=None): | |
"""Get values from a potentially nested collection without raising errors""" | |
return reduce(lambda x, y: safe_get(x, y, default), keys, collection) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment