A fast method for calculating the probabilities of items in a distribution using python
Question: Is there a quick method or a function than automatically computes
probabilities of items in a distribution without importing random?

For instance, consider the following distribution (dictionary):

    
    
    y = {"red":3, "blue":4, "green":2, "yellow":5}
    

  1. I would like to compute the probability of picking each item.
  2. I would also like to compute the probability of picking a red and two greed.

Any suggestions?


Answer: For the frequencies:

    
    
       y = {"red":3, "blue":4, "green":2, "yellow":5} 
       frequencies = {key:float(value)/sum(y.values()) for (key,value) in y.items()}
    

And the probabilities of having a given combination is the probability of each
of them multiplied by the previous ones.

    
    
       combination = ["red", "green", "green"]
       prob = 1. # initialized to 1
       for ii in combination:
           prob *= frequencies[ii]
       print prob
       0.00437317784257
    

Does that sound reasonable?

