Created
January 4, 2013 21:30
-
-
Save bruth/4456252 to your computer and use it in GitHub Desktop.
Recursively flatten a list of lists and tuples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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