Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Flatten a one-level nested list

Flatten only the top-level nested lists inside a list, preserving deeper nested structures and non-list items.

Python practice6 minList & Dictionary PatternsBeginnerLast updated March 20, 2026

Problem statement

Given a list that may contain other lists as elements (but only one level deep), return a new list where any child lists are flattened into the outer list. Do not recursively flatten deeper nested lists; keep non-list items (tuples, dicts, etc.) unchanged. Behavior rules: - If an element is a list, extend the result with its elements. - If an element is not a list, append it as-is. - Do not modify the input list. Implement: flatten_one_level(lst) -> list

Task

Write a function that takes a list which may contain other lists one level deep and returns a single-level list with those inner list elements lifted into the outer list.

Examples

Simple flatten

Input

flatten_one_level([1, [2, 3], 4])

Output

[1, 2, 3, 4]

The inner list [2, 3] is flattened into the outer list; other elements kept.

Input format

A single Python list which may contain other lists as top-level elements.

Output format

A Python list with one level of nesting removed from any inner lists.

Constraints

Only flatten elements that are instances of list. Do not recursively flatten deeper lists. Do not use external libraries.

Samples

Sample 1

Input

flatten_one_level([[1,2],[3],[4]])

Output

[1, 2, 3, 4]

All top-level lists are flattened into a single list.