19 Sep
2019
19 Sep
'19
12:07 p.m.
Its faster than the built in set type. Uniqueness of values isn't a requirement. The values need to be comparable so that they can be sorted. This allows a linear time complexity. That's basically the only restraint on the values. Here are some speed test results and pseudocode. def naive(a,b): res = [x for x in a if x not in b] def set_test(a,b): aset = set(a) bset = set(b) res = aset - bset res= list(res) For A not in B: trying A 10000 elements B 50000 elements naive test 10.285029 s set test 0.008001 s listex test 0.004000 s For A subset of B: trying A 100000 elements B 500000 elements naive too long to wait :-) set test 0.125013 s listex test 0.054005s