I have the following list, where the 1st element is a generic value and the second is the number of occurrences of that value:
mylist=[(2, 45), (3, 21), (4, 12), (5, 7),
(6, 2), (7, 2), (8, 3), (9, 2),
(10, 1), (11, 1), (15, 1), (17, 2), (18, 1)]
and I want to compute the CCDF (Complementary Cumulative Distribution Function) of those values appearing as second element of each tuple.
My code:
ccdf=[(i,sum(k>=i for i in mylist)) for i,k in mylist]
But this is not working as the outcome is void:
ccdf=[(2, 0), (3, 0), (4, 0), (5, 0),
(6, 0), (7, 0), (8, 0), (9, 0),
(10, 0), (11, 0), (15, 0), (17, 0), (18, 0)]
The sum of values in the second position in each tuple is 100. So, I would like to know how many times I have a value >= 2 (100-44=56), how many times I have a value >= 3 (100-44-21=35), and so forth. The result would thus be:
ccdf=[(2, 56), (3, 35), (4, 23), (5, 16),
(6, 14), (7, 12), (8, 9), (9, 7),
(10, 6), (11, 5), (15, 4), (17, 3), (18, 1)]
What is wrong in my list comprehension?