Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Flatten a single-level list of lists

Flatten only one level of nesting: turn a list of lists (and/or tuples and scalars) into a single list of elements.

Python practice16 minLists & TuplesIntermediateLast updated March 17, 2026

Problem statement

Write a function flatten_once(nested) that accepts a list which may contain other lists or tuples as elements and returns a new list with exactly one level of flattening applied. For each element in the input list: - If the element is a list or tuple, extend the output with its elements (one level deep). - Otherwise, append the element as-is. Do not perform deep flattening: if an inner element contains nested lists beyond the first level, leave those nested structures intact as elements.

Task

Implement a function that flattens one level of nesting for a list containing sublists/tuples and other elements.

Examples

Basic flatten

Input

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

Output

[1, 2, 3, 4]

Each inner list is expanded one level into the resulting list.

Input format

A single Python list which may contain lists, tuples, or other objects as elements.

Output format

A list with one level of flattening applied.

Constraints

Only flatten one level. Preserve the order of elements. Result must be a list.

Samples

Sample 1

Input

[['a'], ['b', 'c'], []]

Output

['a', 'b', 'c']

Empty inner lists contribute nothing; other inner lists are expanded.