def select(*selector_key, invert=False):
    """Takes in a selector key and returns a selector that returns true
    for selected values and false for non-selected values. This is how
    cuts are applied in ntupledicts.

    Args:
        selector_key: If a single number, the selector will return true
            for that number. If two numbers, the selector will return
            true for numbers in that range, inclusive. If a list, will
            treat each element of a list as a selector and logical OR
            them together. This is done instead of AND, as AND can
            simply be achieved by applying multiple selectors.
        invert: Invert the selection. False by default.

    Returns:
        A selector, a function that returns true for some values and
        false for all others.

    Raises:
        ValueError: for invalid selector keys.
    """

    if len(selector_key) == 1:
        key_contents = next(iter(selector_key))
        if isinstance(key_contents, list):
            selector = lambda val: any(map(
                lambda sub_selector: sub_selector(val),
                key_contents))
        elif isinstance(key_contents, (float, int)):
            selector = lambda val: val == next(iter(selector_key))
        else:
            raise ValueError("Invalid selector key type: {}."
                    .format(type(key_contents)))
    elif len(selector_key) == 2:
        selector = lambda val: selector_key[0] <= val <= selector_key[1]
    else:
        raise ValueError("Invalid selector key length: {}. Read the docs!"
                         .format(selector_key))

    return lambda val: invert != selector(val)