8.5 Using more complex structures – maps of lists
In Chapter 4, we looked at the basic data structures available in Python. Those recipes generally looked at the various structures in isolation.
We’ll look at a common combination structure—the mapping from a single key to a list of related values. This can be used to accumulate detailed information about database or log records identified by a given key. This recipe will partition a flat list of details into lists organized by shared key values.
This blurs into class design because we can often leverage Python’s built-in classes for this kind of work. This can reduces the volume of unique, new code we have to write.
8.5.1 Getting ready
We’ll look at a mapping from a string to a list of instances of a class we’ll design. We’re going to start with some raw log entries from an application, decompose each line into individual fields...