An alternative to dictionaries in Python is namedtuple. As the name implies, a named tuple is a tuple where each entry can be accessed via a name instead of being accessed via its index. The benefits of using named tuples instead of dictionaries are the following:
- Named tuples fields can be accessed with their field names and dot notation: foo.x allows us to access the x field of the foo tuple.
- Named tuples are as efficient as tuples. Accessing a field of a tuple is much faster than a field of a dictionary. With a dictionary, each field is accessed via its hash value, and a lookup is necessary for each access to a dictionary field. This is not the case with tuples and named tuples. Their fields are immediately accessible. ...