How to choose keys from a python dictionary based on weighted probability? : <p>I have a Python dictionary where keys represent some item and values represent some (normalized) weighting for said item. For example:</p>

<pre><code>d = {'a': 0.0625, 'c': 0.625, 'b': 0.3125}
# Note that sum([v for k,v in d.iteritems()]) == 1 for all `d`
</code></pre>

<p>Given this correlation of items to weights, how can I choose a key from <code>d</code> such that 6.25% of the time the result is 'a', 32.25% of the time the result is 'b', and 62.5% of the result is 'c'? </p>
