Skip to content

Instantly share code, notes, and snippets.

@onelharrison
Last active January 8, 2021 09:09
Show Gist options
  • Save onelharrison/b3c89cc4bdda9d44db07e0aa8cc3c330 to your computer and use it in GitHub Desktop.
Save onelharrison/b3c89cc4bdda9d44db07e0aa8cc3c330 to your computer and use it in GitHub Desktop.
Implementation of a dig function in Python
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