overwrite set behavior

Marco Bizzarri marco.bizzarri at gmail.com
Thu Sep 4 16:12:32 CEST 2008


On Thu, Sep 4, 2008 at 3:07 PM, Maric Michaud <maric at aristote.info> wrote:
> Le Thursday 04 September 2008 14:31:23 Michele Petrazzo, vous avez écrit :
>> Marco Bizzarri wrote:
>> > looking at the source, maybe you could create a subclass of Set
>> > redefining the __contains__ method?
>>
>> Made some tries, but __contains__ are never called
>>
>
> No, __contains__ is only called  with "in" operator, not for internal hashing.
> Anyway this solution is bad, you'll need to compare the new element with all
> the set contain, which would result in a O(n) algorithm for adding elements
> to the set in place of the O(1) it use.
>

Thanks for the clarification, Maric; I take notices to watch source
more closely next time (( hopefully, before writing a wrong answer )).

Regards
Marco

> _____________
>
> Maric Michaud
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Marco Bizzarri
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.com/



More information about the Python-list mailing list