import operator


def compare(this, val1, compare_operator, val2):
    """Compare two values based on the provided operator."""
    operators = {
        "==": operator.eq,
        "!=": operator.neg,
        "<": operator.lt,
        "<=": operator.le,
        ">=": operator.ge,
        ">": operator.gt,
    }
    if compare_operator not in operators:
        return False
    return operators[compare_operator](val1, val2)