def select_rewrite_expression(settings, name, exprs):
    """
    Given an expression name and a list of expressions,
    tries to select an expression with the highest selectivity
    for use in AST re-writing.
    """
    # Get all the sets
    sets = [e.left.value for e in exprs]

    # Count the occurances of each element
    counts = defaultdict(int)
    total = 0
    for s in sets:
        for item in s:
            counts[item] += 1
            total += 1

    # Compute the hamonic mean of avg frequency per set
    scores = []
    total = float(total)
    for idx, s in enumerate(sets):
        freqs = [counts[i]/total for i in s]
        hm = util.harmonic_mean(freqs)
        scores.append((hm, exprs[idx]))

    # Reverse sort, get the highest score
    sorted(scores, key=lambda p: p[0], reverse=True)

    # Check if we hit our minimum threshold
    if scores[0][0] < settings.min_density:
        return None

    # Return the highest score
    return scores[0][1]
dataset/ETHPy150Open armon/pypred/pypred/contains.py/select_rewrite_expression/original