for new_key, value in list(structure.items()):
    flatten(value, new_key, path + '_' + key, flattened)
Flattening a list of dicts of lists of dicts (etc) of unknown depth in Python (nightmarish JSON structure)