def _flatten_dict_nest_repeats(d, prefix):
    assert type(d) == dict
    assert type(prefix) == list

    for key, value in d.items():
        new_prefix = prefix + [key]
        if type(value) == dict:
            for pair in _flatten_dict_nest_repeats(value, new_prefix):
                yield pair
        elif type(value) == list:
            repeats = []
            for i, item in enumerate(value):
                item_prefix = list(new_prefix)  # make a copy
                if type(item) == dict:
                    repeat = {}
                    for path, value in \
                            _flatten_dict_nest_repeats(item, item_prefix):
                        # TODO: this only considers the first level of repeats
                        repeat.update({u"/".join(path[1:]): value})
                    repeats.append(repeat)
                else:
                    repeats.append({u"/".join(item_prefix[1:]): item})
            yield (new_prefix, repeats)
        else:
            yield (new_prefix, value)
Return a list of XPath, value pairs.
dataset/ETHPy150Open kobotoolbox/kobocat/onadata/apps/logger/xform_instance_parser.py/_flatten_dict_nest_repeats