def difference_by(a, b, fn): b = set(map(fn, b)) return [item for item in a if fn(item) not in b]