Using more complex structures – maps of lists
In Chapter 4, Built-In Data Structures Part 1: Lists and Sets, we looked at the basic data structures available in Python. The 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 an object identified by a given key. This recipe will transform a flat list of details into details structurally organized by shared key values.
Getting ready
In order to create a more complex data structure, like a map that contains lists, we're going to need more complex data. To get ready, we're going to start with some raw log data, decompose it into individual fields, and then create individual Event
objects from the fields of data. We can then reorganize and regroup the Event
objects into lists associated with common attribute values.