April 2018
Intermediate to advanced
408 pages
10h 42m
English
When we use a construct such as ((f(x), x) for x in C), we've used wrapping to create a multi-valued tuple while also applying a mapping. This is a common technique to save derived results to create constructs that have the benefits of avoiding recalculation without the liability of complex state-changing objects.
This is part of the example shown in Chapter 4, Working with Collections, to create the trip data from the path of points. The code looks like this:
from ch02_ex3 import ( float_from_pair, lat_lon_kml, limits, haversine, legs) path = float_from_pair(float_lat_lon(row_iter_kml(source))) trip = tuple( (start, end, round(haversine(start, end), 4)) for start, end in legs(iter(path)))
We can revise ...