Back to Practice
#0004

Flatten One Level of Nested Lists

EasyPython10 min10 XP

Problem

Given a list of lists, return a new list containing every inner item in left-to-right order.

Why This Matters

Flattening appears when APIs, grouped rows, or batched data return nested lists and you need a single sequence.

Function Signature

def flatten_once(groups):

Examples

Example 1
Inputgroups = [[1, 2], [], [3, 4]]
Output[1, 2, 3, 4]

The empty inner list contributes nothing, and the remaining values keep order.

Constraints

  • Only flatten one level.
  • Inner lists may be empty.
  • Do not mutate the input lists.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 4 hidden categories
Includes empty group
Input[[1, 2], [], [3, 4]]
Expected[1, 2, 3, 4]

The nested loops visit inner lists in order.

Hidden Test Categories
All inner lists emptyStrings as itemsSingle inner listMany small groups