Building namedtuples with functional constructors
There are three ways we can build namedtuple
instances. The choice of technique we use is generally based on how much additional information is available at the time of object construction.
We've shown two of the three techniques in the examples in the previous section. We'll emphasize the design considerations here. It includes the following choices:
- We can provide the parameter values according to their positions. This works out well when there are one or more expressions that we were evaluating. We used it when applying the
haversine()
function to thestart
andend
points to create aLeg
object.Leg(start, end, round(haversine(start, end),4))
- We can use the
*argument
notation to assign parameters ...
Get Functional Python Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.