June 2017
Beginner to intermediate
296 pages
7h 4m
English
The last step is to transform the pairs of total number of friends and the number of times that key was encountered to an actual average value:
That's what this final line does with mapValues:
averageByAge = totalsByAge.mapValues(lambda x: x[0] / x[1])
Again, we're just receiving the value part of our key/value pair into our lambda function because we're calling mapValues and leaving the keys untouched.
So the age in this example, 33, will remain untouched and not even shown to us in our lambda function:
However, our lambda ...
Read now
Unlock full access