def average_match(pairwise, e, l, ignore_self=False):
    """The average match between element e and list l"""
    # filter out ourself as this will give us a nice 1.0 value
    # the problem with this is if we are a list of 1, anything will have a better value!
    if ignore_self:
        l = [x for x in l if x != e]
    if len(l) == 0:
        return 0
    values = [pairwise[e][x] for x in l]
    return 1.0*sum(values)/len(values)