def keyslice_pairs(pairs, include=None, omit=None, rename=None, key=None):
    """Filter (key, value) pairs by key and return a subset.

    :param pairs: an iterable of ``(key, value)`` pairs (2-tuples).

    :param include: optional, a sequence of key values.  If supplied, only
        pairs whose key is a member of this sequence will be returned.

    :param omit: optional, a sequence of key values. If supplied, all pairs
        will be returned, save those whose key is a member of this sequence.

    :param rename: optional, a mapping or sequence of 2-tuples specifying a
        key-to-key translation.  A pair whose key has been renamed by this
        translation will always be emitted, regardless of *include* or *omit*
        rules.  The mapping will be converted to a dict internally, and keys
        must be hashable.

    :param key: optional, a function of one argument that is used to extract a
        comparison key from the first item of each pair.  Similar to the
        ``key`` parameter to Python's ``sort`` and ``sorted``.  Useful for
        transforming unicode keys to bytestrings with ```key=str``, adding or
        removing prefixes en masse, etc.

    :returns: yields ``(key, value)`` pairs.

    """
    if include and omit:
        raise TypeError('received include and omit, specify only one')

    include = set(include) if include else False
    omit = set(omit) if omit else False
    rename = dict(to_pairs(rename)) if rename else False
    keyfunc = key
    del key

    for key, value in pairs:
        if keyfunc:
            key = keyfunc(key)
        if rename or key in rename:
            yield (rename[key], value)
            continue
        if include:
            if key not in include:
                continue
        elif omit:
            if key in omit:
                continue
        yield key, value
dataset/ETHPy150Open jek/flatland/flatland/util/base.py/keyslice_pairs/operator `and` -> `or`