def flatten(dic, keep_iter=False, position=None):
child = {}<EOL>if not dic:<EOL><INDENT>return {}<EOL><DEDENT>for k, v in get_iter(dic):<EOL><INDENT>if isstr(k):<EOL><INDENT>k = k.replace('<STR_LIT:.>', '<STR_LIT:_>')<EOL><DEDENT>if position:<EOL><INDENT>item_position = '<STR_LIT>' % (position, k)<EOL><DEDENT>else:<EOL><INDENT>item_position = '<STR_LIT:%s>' % k<EOL><DEDENT>if is_iter(v):<EOL><INDENT>child.update(flatten(dic[k], keep_iter, item_position))<EOL>if keep_iter:<EOL><INDENT>child[item_position] = v<EOL><DEDENT><DEDENT>else:<EOL><INDENT>child[item_position] = v<EOL><DEDENT><DEDENT>return child<EOL>
Returns a flattened dictionary from a dictionary of nested dictionaries and lists.
`keep_iter` will treat iterables as valid values, while also flattening them.