Last active
December 14, 2015 09:49
-
-
Save jtushman/5067266 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
from copy import deepcopy | |
def dig(hash,*keys): | |
""" | |
digs into an dict, if anything along the way is None, then simply return None | |
So instead of | |
entry['bids']['maxCpm']['amount']['microAmount'] | |
you do | |
dig(entry,'bids','maxCpm','amount','microAmount') | |
""" | |
end_of_chain = deepcopy(hash) | |
for key in keys: | |
if isinstance(end_of_chain,dict) and key in end_of_chain: | |
end_of_chain = end_of_chain[key] | |
else: | |
return None | |
return end_of_chain |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment