April 2018
Intermediate to advanced
408 pages
10h 42m
English
A mapping like the collections.Counter method is a great optimization for doing reductions that create counts (or totals) grouped by some value in the collection. A more typical functional programming solution to grouping data is to sort the original collection, and then use a recursive loop to identify when each group begins. This involves materializing the raw data, performing a
sort, and then doing a reduction to get the sums or counts for each key.
We'll use the following generator to create a simple sequence of distances transformed into bins:
quantized = (5*(dist//5) for start, stop, dist in trip)
We divided ...