fast way to filter a set?

Peter Otten __peter__ at web.de
Wed Sep 17 13:13:09 EDT 2003


Nicola Mingotti wrote:

> fortepianissimo at yahoo.com.tw (Fortepianissimo) writes:
> 
>> I know I can do things like
>> 
>> s=Set(range(1,11))
>> s=Set(filter(lambda x:x%2==0,s))
>> 
>> But this seems a bit slow since filter returns a list which then must
>> be converted back to a set. Any tips? Thanks!
> 
> Can you ?
> I tried python2.3 and 2.2 and it replies
> : "NameError: name 'Set' is not defined" .

In 2.3 it works if you do

from sets import Set

first.

Peter




More information about the Python-list mailing list