Flatten nested dictionaries, compressing keys
Basically the same way you would flatten a nested list, you just have to do the extra work for iterating the dict by key/value, creating new keys for your new dictionary and creating the dictionary at final step. import collections def flatten(d, parent_key=”, sep=’_’): items = [] for k, v in d.items(): new_key = parent_key … Read more