Sets in Python
Thomas Wouters
thomas at xs4all.net
Wed Jan 31 04:31:46 EST 2001
On Tue, Jan 30, 2001 at 05:26:18PM +0000, Michael Hudson wrote:
> "Magnus Lie Hetland" <mlh at idi.ntnu.no> writes:
> > And if one was to write a small wrapper of some kind --
> > is there any way to implement "x in s" without a linear search?
> > Or does the "in" operator always loop from 0 and up?
> > (It would certainly be nice to be able to override it...)
> Tried __contains__?
__contains__ only works in Python 1.6 and higher, though. In older versions
of Python, you have to supply a __getitem__ that takes an int as key and
throws IndexError when you're done.
--
Thomas Wouters <thomas at xs4all.net>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
More information about the Python-list
mailing list