← All Exercises

Python Coroutine Pipeline

advancedpython~35min

Background

Coroutine pipelines enable streaming data processing without loading all data into memory, useful for ETL and log processing.

Problem

Create a pipeline of coroutines that filter, transform, and aggregate streamed data items using the send() protocol.

Input

A list of data items to process through the pipeline.

Output

The aggregated result after filtering and transforming.

Sample tests

Sample 1

Input: [1, -2, 3, -4, 5] (filter positive, square, sum)
Expected: 35 (1+9+25)

Your solution

Learning objective

Learn coroutine-based pipelines, the send() protocol, and coroutine priming.