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
def key_chain(data, *args, default=None): | |
for key in args: | |
if isinstance(data, dict) and key in data: | |
data = data[key] | |
elif isinstance(data, (list, tuple)) and isinstance(key, int): | |
try: | |
data = data[key] | |
except IndexError: | |
return default | |
else: |