Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Skip Empty Strings

Filter out empty or whitespace-only strings from a list while preserving order.

Python practice10 minLoops & IterationBeginnerLast updated March 15, 2026

Problem statement

Given a list of strings, return a new list where all strings that are empty or contain only whitespace characters are removed. Preserve the relative order of the remaining strings.

Task

Use iteration and string methods to filter a list, skipping entries that are empty or contain only whitespace.

Examples

Remove empty and whitespace-only strings

Input

skip_empty(["a", "", "b", " ", "c"])

Output

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

Empty string and a single-space string are removed, others kept in order.

Input format

A list of strings.

Output format

A list of strings containing only non-empty, non-whitespace-only entries.

Constraints

Do not modify the original list; return a new list. Use only Python standard string methods.

Samples

Sample 1

Input

skip_empty(["hello", " world "])

Output

['hello', ' world ']

Strings with surrounding or internal whitespace but containing characters are kept unchanged.