June 2017
Beginner
352 pages
8h 39m
English
Now that you understand the generators individually, we'll arrange both of them into a lazy pipeline. We'll be using take() and distinct() together to fetch the first three unique items from a collection:
def run_pipeline(): items = [3, 6, 6, 2, 1, 1] for item in take(3, distinct(items)): print(item)
Notice that the distinct() generator only does just enough work to satisfy the demands of the take() generator which is iterating over it
Read now
Unlock full access