Skip to content

Instantly share code, notes, and snippets.

@kasperjunge
Last active July 29, 2022 11:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kasperjunge/96fb194d90c6917684aba16380008531 to your computer and use it in GitHub Desktop.
Save kasperjunge/96fb194d90c6917684aba16380008531 to your computer and use it in GitHub Desktop.
Flatten list
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