4.4 Shrinking lists – deleting, removing, and popping
There will be many times when we’ll want to remove items from a list collection. We might delete items from a list, and then process the items that are left over.
Removing unneeded items has a similar effect to using filter() to create a copy that has only the needed items. The distinction is that a filtered copy will use more memory than deleting items from a list. We’ll show both techniques for removing unwanted items from a mutable list.
4.4.1 Getting ready
We have a spreadsheet that is used to record fuel consumption on a large sailboat. See Table 4.1 for the data.
For more background on this data, refer to the Slicing and dicing a list recipe earlier in this chapter. The get_fuel_use() function will collect the raw data. It’s important to note that the structure of this data—each fact spread among three separate rows—is perfectly...