Skip to Content
Hands-On Reactive Programming with Python
book

Hands-On Reactive Programming with Python

by Romain Picard
October 2018
Intermediate to advanced
420 pages
10h 26m
English
Packt Publishing
Content preview from Hands-On Reactive Programming with Python

Using named tuples

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. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Programming with Design Patterns

Python Programming with Design Patterns

James W. Cooper

Publisher Resources

ISBN: 9781789138726Supplemental Content