def weighted(criterias_weights):
    """Return callable criteria with weighted sub-criteria values

    This allows you to create a new criteria function by mixing others.

        >>> weighted([(equal, 1)])("foo", "bar")
        0.0
        >>> weighted([(equal, 1)])("foo", "foo")
        1.0
        >>> weighted([(equal, 1), (size, 1)])("foo", "bar")
        0.5
        >>> weighted([(equal, 3), (size, 1)])("foo", "bar")
        0.25

    """
    def wc(a, b):
        s = 0
        tot_wh = 0
        for cr, wh in criterias_weights:
            s += float(cr(a, b)) * wh
            tot_wh += wh
        return s / tot_wh
    return wc