Functional data pipeline using map → filter → reduce Dry Run in PYTHON

Functional data pipeline using map → filter → reduce 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.

Functional data pipeline using map → filter → reduce Program Code

from functools import reduce

# Sales data: (product, category, price, quantity)
sales = [
    ("Laptop", "Electronics", 800, 5),
    ("Mouse", "Electronics", 25, 30),
    ("Desk", "Furniture", 450, 3),
    ("Chair", "Furniture", 200, 8),
    ("Monitor", "Electronics", 300, 6),
    ("Lamp", "Furniture", 50, 12)
]

# Pipeline: Electronics only → calculate revenue → sum total
total_electronics_revenue = reduce(
    lambda acc, x: acc + x,
    map(
        lambda s: s[2] * s[3],  # price * quantity
        filter(lambda s: s[1] == "Electronics", sales)
    )
)

# Pipeline: Furniture items with revenue > 1000
high_value_furniture = list(filter(
    lambda x: x[1] > 1000,
    map(
        lambda s: (s[0], s[2] * s[3]),  # (product, revenue)
        filter(lambda s: s[1] == "Furniture", sales)
    )
))

print(f"Total Electronics Revenue: ${total_electronics_revenue}")
print(f"High-value Furniture (>$1000): {high_value_furniture}")

View the complete Special programs page.

Program Console Functional data pipeline using map → filter → reduce Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.