Data cleaning using filter() Dry Run in PYTHON

Data cleaning using filter() is an interactive PYTHON dry run visualizer from the Special programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.

This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.

Data cleaning using filter() Program Code

# Dirty data with various issues
dirty_data = [
    "John Doe", "", "  ", "Jane Smith", None, "   Bob Brown   ",
    "Alice", "  ", "Charlie", "", "  David Lee  ", None, "Eve"
]

# Remove None and empty strings, strip whitespace
cleaned = list(filter(
    lambda x: x and isinstance(x, str) and x.strip(),
    dirty_data
))

# Strip whitespace from remaining strings
cleaned = list(map(str.strip, cleaned))

print("Original dirty data:", dirty_data)
print("Cleaned data:", cleaned)

# Filter valid email addresses
emails = [
    "user@example.com",
    "invalid",
    "test@gmail.com",
    "",
    "  admin@company.com  ",
    "noatsymbol",
    None
]

valid_emails = list(filter(
    lambda e: e and isinstance(e, str) and "@" in e and "." in e.split("@")[1],
    map(str.strip, filter(None, emails))
))

print(f"\nValid emails: {valid_emails}")

View the complete Special programs page.

Program Console Data cleaning using filter() Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.