Using stacked generator expressions
In the Writing generator functions with the yield statement recipe, we created a simple generator function that performed a single transformation on a piece of data. As a practical matter, we often have several functions that we'd like to apply to incoming data.
How can we stack or combine multiple generator functions to create a composite function?
Getting ready
We have a spreadsheet that is used to record fuel consumption on a large sailboat. It has rows which look like this:
date |
engine on |
fuel height |
engine off |
fuel height | |
Other notes | ||
10/25/2013 |
08:24 |
29 |
13:15 |
27 | |
calm seas - anchor solomon's island | ||
10/26/2013 |
09:12 |
27 |
18:25 |
22 | |
choppy - anchor in jackson's creek |
For more background on this data, see the Slicing and dicing a list recipe in Chapter 4, Built-in Data Structures – list, set, dict.
As a sidebar, we can take the data like this. We'll look at this in detail in the Reading delimited files with the csv module recipe in...