Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Compose multiple functions into a single map pipeline

Create a reusable map pipeline that applies a sequence of functions to each item in an iterable.

Python practice21 minFunctions as Objects (Lambda, Map/Filter)AdvancedLast updated March 20, 2026

Problem statement

You often need to apply several transformations to every element of a sequence. Instead of nesting maps or writing a loop each time, build a reusable pipeline that composes multiple functions and applies them in order to each element. Write compose_map(funcs, iterable) that: - Accepts funcs: an iterable (e.g., list or tuple) of callables. Each callable receives the output of the previous one. - Accepts iterable: any iterable of input values. - Returns a list where each input element has been transformed by every function in funcs in the same order. Behavior details: - If funcs is empty, compose_map should return a list constructed from iterable (no transformation). - The functions may change types (e.g., int -> str). The pipeline must pass the intermediate result to the next function.

Task

Implement compose_map(funcs, iterable) which chains multiple callables and returns a list of transformed items.

Examples

Double then increment numbers

Input

compose_map([lambda x: x * 2, lambda x: x + 1], [1, 2, 3])

Output

[3, 5, 7]

Each number is doubled then incremented: 1->2->3, 2->4->5, 3->6->7.

Input format

Two arguments: (1) funcs: iterable of callables, (2) iterable: any iterable of input items.

Output format

A list containing transformed items (Python list repr).

Constraints

- Do not modify the original iterable in-place. - Always return a list. - Functions are applied in the order provided.

Samples

Sample 1

Input

compose_map([str, lambda s: s + '!'], [1, 2])

Output

['1!', '2!']

Convert numbers to strings then append '!'.