def makehist(vals, incr=1, normalize=0):
    """Makes a histogram for the given vals and returns a dict.
    Incr is how much each item counts for
    If normalize is true, then the sum of return values is normalize.
    """
    ret = {}
    sum = 0
    for v in vals:
        if v not in ret:
            ret[v] = 0
        ret[v] += incr
        sum += incr
    if normalize:
        for k in ret:
            ret[k] *= (normalize/sum)
    return ret