filter list fast

2006-03-18 Thread lars_woetmann
I have a list I filter using another list and I would like this to be
as fast as possible
right now I do like this:

[x for x in list1 if x not in list2]

i tried using the method filter:

filter(lambda x: x not in list2, list1)

but it didn't make much difference, because of lambda I guess
is there any way I can speed this up

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: filter list fast

2006-03-18 Thread lars_woetmann
Thanks all, sets work like i charm

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: filter list fast

2006-03-18 Thread lars_woetmann
comparing
[x for x in list1 if x not in list2]
with
set1, set2 = set(list1), set(list2)
list(set1-set2)

gives something like
len(list2) speedup
--
10010
1000  100
11000

the speedup is constant for different len(list1)

-- 
http://mail.python.org/mailman/listinfo/python-list