Denormalize/flatten list of nested objects into dot separated key value pairs
It would have simpler if my nested objects were dictionaries, but these are list of dictionaries. Example: all_objs1 = [{ 'a': 1, 'b': [{'ba': 2, 'bb': 3}, {'ba': 21, 'bb': 31}], 'c': 4 }, { 'a': 11, 'b': [{'ba': 22, 'bb': 33, 'bc': [{'h': 1, 'e': 2}]}], 'c': 44 }] I expect output in following format: [ {'a': 1, 'b.ba': 2, 'b.bb': 3, 'c': 4}, {'a': 1, 'b.ba': 21, 'b.bb': 31, 'c': 4}, {'a': 11, 'b.ba': 22, 'b.bb': 33, 'bc.h': 1, 'bc.e': 2, 'c': 44}, ] Basically, number of flattened objects generated will be equal to (obj * depth) With my current code: def flatten(obj, flattened_obj, last_key=''