Advanced
Transform a token stream with an async generator
words(text) is an async generator that yields the words of a text, one at a time, like a model streaming tokens. Write two things: shout(stream), an async generator that yields each item of another async stream in upper case, and async def collect(stream) that returns all items of an async stream as a list.
The program should print ['HELLO', 'BIG', 'WORLD'].
What Check tests
collect(shout(words(...)))gives the upper-case words- An empty text gives an empty list
shoutis an async generator functionshoutis lazy: the first item arrives before the stream ends- The program prints the list
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.