also seems like a use case for map_reduce(). at the very minimum, the implementation of create_filter() should use a set instead of a list, which is o(n^2)