def flatten(l):
l = list(l)<EOL>i = <NUM_LIT:0><EOL>while i < len(l):<EOL><INDENT>while isinstance(l[i], list):<EOL><INDENT>if not l[i]:<EOL><INDENT>l.pop(i)<EOL>i -= <NUM_LIT:1><EOL>break<EOL><DEDENT>else:<EOL><INDENT>l[i:i + <NUM_LIT:1>] = l[i]<EOL><DEDENT><DEDENT>i += <NUM_LIT:1><EOL><DEDENT>return l<EOL>
Flattens a hierarchy of nested lists into a single list containing all elements in order

:param l: list of arbitrary types and lists
:returns: list of arbitrary types