Last active
September 27, 2015 17:38
-
-
Save terrasea/1307269 to your computer and use it in GitHub Desktop.
Flattens a list of lists into just 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
#The list of lists | |
list_of_lists = [range(4), range(7)] | |
#flatten the lists | |
flattened_list = [x for y in list_of_lists for x in y] | |
#or using itertools | |
list(itertools.chain(*list_of_lists)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment