Python list comparison: Can this code run faster?
So it seems you primarily want to use your callback functions to pull the value to compare out of an object, if you don't mind simplifying how compared items are returned, a faster and simpler approach would be:

def simple_compare(li1, li2, value_func1=None, value_func2=None):
        s1, s2 = set(map(value_func1, li1)), set(map(value_func2, li2))
        common = s1.intersection(s2)
        s1_diff, s2_diff = s1.difference(s2), s2.difference(s1)
        return common, s1_diff, s2_diff

&gt;&gt;&gt; simple_compare(li1, li2, value_func1=f)
&lt;&lt;&lt; (set([1, 3]), set([2]), set([5]))

&gt;&gt;&gt; compare_lists(li1, li2, value_func1=f)
&lt;&lt;&lt; (([{'v': 1}, {'v': 3}], [1, 3]), [{'v': 2}], [5])


Which depending on actual use case, might be something you could live with. It's definitely a lot faster:

&gt;&gt;&gt; timeit x = simple_compare(xrange(10000), xrange(10000))
100 loops, best of 3: 2.3 ms per loop

&gt;&gt;&gt; timeit x = compare_lists(xrange(10000), xrange(10000))
10 loops, best of 3: 53.1 ms per loop