creating cumulative percentage from a dictionary of data
<p>Given a dictionary (or Counter) of tally data like the following:</p>

<pre><code>d={'dan':7, 'mike':2, 'john':3}
</code></pre>

<p>and a new dictionary "d_cump" that I want to contain cumulative percentages</p>

<pre><code>d_cump={'mike':16, 'john':41, 'dan':100}
</code></pre>

<p>EDIT: Should clarify that order doesn't matter for my input set, which is why I'm using a dictionary or counter.  Order does matter when calculating cumulative percentages so I need to sort the data for that operation, once I have the cumulative percentage for each name then I put it back in a dictionary since again, order shouldn't matter if I'm looking at single values.</p>

<p>What is the most elegant/pythonic way to get from d to d_cump?</p>

<p>Here is what I have seems a bit clumsy:</p>

<pre><code>from numpy import cumsum
d={'dan':7, 'mike':2, 'john':3}
sorted_keys = sorted(d,key=lambda x: d[x])
perc = [x*100/sum(d.values()) for x in cumsum([ d[x] for x in sorted_keys ])]
d_cump=dict(zip(sorted_keys,perc))

&gt;&gt;&gt; d_cump
{'mike': 16, 'john': 41, 'dan': 100}
</code></pre>
