1 2 3 4 5 6 7
def flatten_list(thelist): for i in thelist: if isinstance(i, list): for k in flatten_list(i): yield k else: yield i