Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Flatten One-Level List

Flatten only one level of nested lists, leaving deeper nested lists intact.

Python practice17 minLoops & IterationIntermediateLast updated March 15, 2026

Problem statement

Write a function that takes a list which may contain elements that are themselves lists. The function should return a new list where any element that is a list is replaced by its elements (one-level flattening). Do not recursively flatten deeper nested lists — they should remain as elements. Preserve the order of elements. This practice focuses on loop control, type checking, and constructing new lists.

Task

Create a function that flattens elements that are lists by one level, practicing iteration and type checks.

Examples

Mixed elements

Input

[1, [2, 3], 4]

Output

[1, 2, 3, 4]

The inner list [2, 3] is flattened into the outer list. Other elements stay the same.

Input format

A single list passed to flatten_one_level(lst). Elements may be any type; lists should be flattened one level.

Output format

A new list with one-level flattening applied.

Constraints

Input list length up to 10,000; total number of elements after flattening will also fit in memory. Only flatten Python list instances (type list). Do not flatten tuples or other iterables.

Samples

Sample 1

Input

[[1,2],[3],[4,5]]

Output

[1, 2, 3, 4, 5]

All inner lists are expanded into the returned list.