Challenge: Chaining and Composing Iterators
Swipe to show menu
Task
Swipe to start coding
Implement the function chained_odds_squared(numbers) that chains together the provided generator functions to process a sequence of numbers:
-
First, use the
filter_oddsgenerator to filter out even numbers from the input iterablenumbers. -
Then, use the
square_numbersgenerator to yield the square of each remaining (odd) number. -
Your function should return an iterator that yields the squared values of odd numbers from the input.
-
Do not create intermediate lists.
Solution
Everything was clear?
Thanks for your feedback!
Section 5. Chapter 7
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Section 5. Chapter 7