from operator import and_
from operator import or_
from functools import reduce


def combine(sub_filters, combinator: str):
    """ Combine filters using a logical combinator """
    assert combinator in ("AND", "OR")
    op = and_ if combinator == "AND" else or_
    return reduce(
        lambda acc, q: op(acc, q) if acc is not None else q,
        sub_filters
    )