April 2018
Intermediate to advanced
408 pages
10h 42m
English
Let's say we want to convert our trip distances from nautical miles to statute miles. We want to multiply each leg's distance by 6076.12/5280, which is 1.150780.
We can do this calculation with the map() function as follows:
map( lambda x: (start(x), end(x), dist(x)*6076.12/5280), trip)
We've defined a lambda that will be applied to each leg in the trip by the map() function. The lambda will use other lambdas to separate the start, end, and distance values from each leg. It will compute a revised distance and assemble a new leg tuple from the start, end, and statute mile distances.
This is precisely like the following generator expression:
((start(x), end(x), dist(x)*6076.12/5280) for x in trip)
We've done ...