June 2017
Beginner
352 pages
8h 39m
English
Perhaps, though, we'd like one long temperature series for Sunday, Monday and Tuesday. Rather than creating a new list by eagerly combining the three lists of temperatures, we can lazily concatenate iterables using itertools.chain():
>>> from itertools import chain>>> temperatures = chain(sunday, monday, tuesday)
The temperatures variable is an iterable object that first yields the values from sunday, followed by those from monday, and finally those from tuesday. Since it's lazy, though, it never creates a single list that contains all of the elements; in fact, it never creates an intermediate list of any sort!
We can now check that all of those temperatures are above freezing point, without the ...
Read now
Unlock full access