June 2017
Beginner
352 pages
8h 39m
English
In addition to the built-in functions, the itertools module contains a wealth of useful functions and generators for processing iterable streams of data.
We'll start demonstrating these functions by solving the first thousand primes problem using built-in sum() with two generator functions from itertools: islice() and count().
Earlier we made our own take() generator function for lazily retrieving the start of the sequence. We needn't have bothered, however, because islice() allows us to perform lazy slicing similar to the built-in list slicing functionality. To get the first 1000 primes we need to do something like:
from itertools import islice, countislice(all_primes, 1000)
But how to generate all_primes? Previously, ...
Read now
Unlock full access