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 thestartandendpoints to create aLegobject.Leg(start, end, round(haversine(start, end),4)) - We can use the
*argumentnotation to assign parameters according to their positions in a tuple. This works out well when we're getting the arguments from another iterable or an existing tuple. We used it when usingmap()to apply thefloat()function to thelatitudeandlongitudevalues...