PIXELBANKv9.1.0
Menu

Problem Statement

Use map, filter, and reduce to process data.

Background

Python provides functional programming tools:

  • map(func, iterable) - apply function to each element
  • filter(func, iterable) - keep elements where func returns True
  • reduce(func, iterable) - combine elements pairwise (from functools)

Your Task

Write a function process_numbers(numbers) that applies various higher-order functions.

Output Format

Return a dictionary with:

  • "doubled": All numbers doubled (use map)
  • "evens": Only even numbers (use filter)
  • "product": Product of all numbers (use reduce)
  • "sum_of_squares": Sum of squared numbers (use map+reduce)

Example:

Input:
[1, 2, 3, 4, 5]
Output:
{'doubled': [2, 4, 6, 8, 10], 'evens': [2, 4], 'product': 120, 'sum_of_squares': 55}
Reasoning:

map(lambda x: x2), filter(lambda x: x%2==0), reduce(lambda a,b: ab)

Constraints:

  • Use map, filter, and reduce from functools
  • Numbers list will have at least 1 element
solution.py

Test Results

0/0
Run code to see test results.
Higher-Order Functions - Medium | PixelBank