Last active
July 29, 2022 11:04
-
-
Save kasperjunge/96fb194d90c6917684aba16380008531 to your computer and use it in GitHub Desktop.
Flatten list
This file contains hidden or 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
from typing import List, Any | |
def flatten_list(list_of_lists: List[List[Any]]) -> List[Any]: | |
"""Merge/flatten a list of lists into one single list. | |
Example: [[1, 2, 3],[4, 5, 6]] --> [1, 2, 3, 4, 5, 6] | |
Args: | |
list_of_lists (List[list]): List of lists to be merged/flattened. | |
Returns: | |
list: Flattened list. | |
""" | |
return [item for sublist in list_of_lists for item in sublist] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment