Lesson guide
What this Python exercise practices
Skip Empty Strings is a beginner practice lesson that focuses on strings, formatting, traversal. It is designed to be solved in about 10 minutes with examples, starter code, and test feedback.
Prerequisites
- Python variables
- String values
- Basic indexing
Difficulty and time
- Level
- Beginner
- Estimated time
- 10 minutes
Practice path
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.
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.
Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.