import math


def calculateFreq( pmf , begin, end ):
    """
    Calculates the frequencies of the pmf betweer [begin, end)

    Args:
        pmf: the probability mass function
        begin: the first (inclusive) element of the interval
        end: the last (exclusive) element of the interval

    Return:
        the probability, to fall between [begin, end)

    Side effect
        Normalize the pmf

    """

    pmf.Normalize()
    items = pmf.GetDict() ;
    filtered = [ prob for value, prob in items.iteritems() 
            if value >= begin and value < end ] 
    prob_sum = math.fsum(filtered)
    return prob_sum