Getting ready...

Let's say we've collected data using a Counter object. For more information on the various collections, see Chapter 4, Built-in Data Structures – list, set, dict, specifically the Using set methods and operators and Avoiding mutable default values for function parameters recipes. In this case, the customers fall into eight categories with approximately equal numbers.

The data looks like this:

    Counter({15: 7, 17: 5, 20: 4, 16: 3, ... etc., 45: 1}) 

In this collection, each key is the number of visits needed to get a full set of coupons. The values are the numbers of times that the visits occurred. In the preceding data that we saw, there were seven occasions where 15 visits were needed to get a full set of coupons. We can ...

Get Modern Python Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.