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 flatten_dict(input_dict, antecedent=None): | |
"""Returns a generator that yields every possible branch of data""" | |
antecedent = antecedent[:] if antecedent else [] | |
if isinstance(input_dict, dict): | |
for key, value in input_dict.items(): | |
if isinstance(value, dict): | |
for nested_dict in flatten_dict( | |
value, antecedent + [key] | |
): | |
yield nested_dict |