Skip to content

Instantly share code, notes, and snippets.

@terrasea
Last active September 27, 2015 17:38
Show Gist options
  • Save terrasea/1307269 to your computer and use it in GitHub Desktop.
Save terrasea/1307269 to your computer and use it in GitHub Desktop.
Flattens a list of lists into just a list
#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