|Flatten a List
All Challenges

Flatten a List

MediumLists

Given a list of lists lst, return a single flattened list containing all elements.


Only flatten one level deep — nested lists inside the inner lists stay as-is.


You'll use this when combining paginated API results, merging database query chunks, or processing batched records.

Examples

Input: flatten([[1, 2], [3, 4], [5]])
Output: [1, 2, 3, 4, 5]
Three sub-lists merged
Input: flatten([[1], [2], [3]])
Output: [1, 2, 3]
Single-element sub-lists
Input: flatten([[1, [2]], [3]])
Output: [1, [2], 3]
Only flatten one level
Input: flatten([])
Output: []
Empty input

Constraints

  • 0 <= len(lst) <= 10,000
  • Each element of lst is itself a list
  • Only flatten one level deep
pythoneditor
Loading Python runtime…