Created
February 2, 2017 01:29
-
-
Save anilpai/01236f830a58571cd95c66953d3d9097 to your computer and use it in GitHub Desktop.
Flatten a list
This file contains 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(lst): | |
''' | |
Flattens a list of lists. | |
''' | |
r = [] | |
for x in lst: | |
if type(x) is list: | |
r.extend(x) | |
else: | |
r.append(x) | |
return r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment