def flatten(d, sep='<STR_LIT:.>'):
def _flatten(e, parent_key='<STR_LIT>', sep='<STR_LIT:.>'):<EOL><INDENT>import collections<EOL>prefix = parent_key + sep if parent_key else '<STR_LIT>'<EOL>if isinstance(e, collections.MutableMapping):<EOL><INDENT>return tuple((prefix + k2, v2) for k, v in e.items() for k2, v2 in _flatten(v, k, sep))<EOL><DEDENT>elif isinstance(e, collections.MutableSequence):<EOL><INDENT>return tuple((prefix + k2, v2) for i, v in enumerate(e) for k2, v2 in _flatten(v, str(i), sep))<EOL><DEDENT>else:<EOL><INDENT>return (parent_key, (e,)),<EOL><DEDENT><DEDENT>return tuple((k, v[<NUM_LIT:0>]) for k, v in _flatten(d, '<STR_LIT>', sep))<EOL>
Flatten a data structure into tuples