Skip to content

23. A Generator Pipeline

Difficulty: Medium · Topic: Generators & iterators

Click-stream lines look like "user,action,ms". Write two generators and a function that chains them:

Your code runs in CPython on our servers against 5 tests, including hidden ones.

Sample test

lines = ["# user,action,ms", "asha,click,120", "ben,view,40", "", "chitra,click,300"]
list(pipeline(lines, 100))

Expected: [{'user': 'asha', 'action': 'click', 'ms': 120}, {'user': 'chitra', 'action': 'click', 'ms': 300}]

Hints

Hint 1Each stage takes an iterable and yields: stages chain like Unix pipes.
Hint 2int(" 42 ") works; int("4.2") and int("x") raise ValueError, which you can catch to skip the line.
Hint 3Compare numbers, not strings: "99" >= "100" is True.

Learn the concepts

More Python problems

All Python problems