Control cmp used with 'in'?

Thomas Wouters thomas at xs4all.nl
Mon Jun 26 03:41:02 EDT 2000


On Mon, 26 Jun 2000 07:05:46 GMT, Stephen Hansen
<stephen at cerebralmaelstrom.com> wrote:
>Matthew Cline <matt at nightrealms.com> wrote in message
>news:52D55.2660$Gh6.168003 at news-west.usenetserver.com...
>> Is there any way to control the function that is used during
>> an 'in' search?

>I believe its the __contains__ method.

In 1.6, yes. In 1.5.2, overloading 'in' is not possible, except by
overloading __getitem__ -- the 'in' implementation for user classes and most
builtin types simply __getsitems__ until it finds a match or reaches
IndexError. In 1.6, it's possible to override it in both and provide a more
efficient implementation. (See 'Objects/rangeobject.c' for an example ;-)

plug-plug-ly y'rs,
Thomas.



More information about the Python-list mailing list