def check_value(val, reference):
    """Return whether value matches reference

    Args:
        val (scalar)
        reference (scalar|list|tuple)
            scalar      check if val == reference
            list        check if check_value(val, ref) for ref in reference
            tuple       check if reference[0] <= val <= reference[1]
    """
    if isinstance(reference, list):
        for ref in reference:
            if check_value(val, ref):
                return True
        return False
    if isinstance(reference, tuple):
        return reference[0] <= val <= reference[1]
    return val == reference