def flatten(nested): try: try: nested + '' except TypeError: pass else: raise TypeError for sublist in nested: for element in flatten(sublist): yield element except TypeError: yield nestedprint list(flatten(['foo', ['bar', ['baz']]]))
Name (required)
email (will not be published) (required)
Website