Skip to content

Instantly share code, notes, and snippets.

@kerenskybr
Created April 20, 2021 17:08
Show Gist options
  • Save kerenskybr/e57130d5eed558d979692ea1e78a9c43 to your computer and use it in GitHub Desktop.
Save kerenskybr/e57130d5eed558d979692ea1e78a9c43 to your computer and use it in GitHub Desktop.
Flattening a list of lists
#Given a list of lists t
flat_list = [item for sublist in t for item in sublist]
flat_list = []
for sublist in t:
for item in sublist:
flat_list.append(item)
# OR
flatten = lambda t: [item for sublist in t for item in sublist]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment