def filter_by_list(data, key_func, term_list, include=True):
    """
    inputs:
        data: iterable to be filtered
        key_func: function that takes a member of d and returns string to compare with term_list
        term_list: strings that are tested to see if they are substrings of key_func return value
        include: if True, then matches are included in output, else matches are excluded
    """
    allow = any if include else lambda x: not any(x)
    return [d for d in data if allow(ext in key_func(d) for ext in term_list)]