Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Problem No 12

Skip Empty Strings

Easy

10 minute session

Summary

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

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']

Explanation

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 input 0

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

Sample output 0

['hello', ' world ']

Explanation 0

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

Code editor
Loading editor…

AI assistant

Ask me anything!

Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.

Chat history is temporary and will not be saved.

02:29 AM

Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.