Created
April 20, 2021 17:08
-
-
Save kerenskybr/e57130d5eed558d979692ea1e78a9c43 to your computer and use it in GitHub Desktop.
Flattening a list of lists
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
#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