Skip to content

Instantly share code, notes, and snippets.

@bruth
Created January 4, 2013 21:30
Show Gist options
  • Save bruth/4456252 to your computer and use it in GitHub Desktop.
Save bruth/4456252 to your computer and use it in GitHub Desktop.
Recursively flatten a list of lists and tuples
def flatten(l, output=None):
if output is None:
output = []
for x in l:
if isinstance(x, (list, tuple)):
flatten(x, output)
else:
output.append(x)
return output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment