I have a list of tuples. For each key I'd like to count the number of distinct values.
For example,
Given the following list:
[(k1, 400), (k1, 500), (k2, 600), (k2, 600), (k3, 600)]
I'd like to produce the following:
{k1: 2, k2: 1, k3: 1}
explanation:
k1
has two values (400, 500). k2
has only one value (600)
What's the Pythonic way to do that?