This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients cool-RR, serhiy.storchaka
Date 2014-09-19.20:57:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1411160235.21.0.465068413045.issue22446@psf.upfronthosting.co.za>
In-reply-to
Content
This is slower.

>>> import timeit
>>> class A(list):
...         def __contains__(self, value):
...             for v in self:
...                 if v == value:
...                     return True
...             return False
... 
>>> timeit.timeit('500 in x', setup='from __main__ import A; x = A(range(1000))', number=10000)
1.1222619999971357
>>> class B(list):
...         def __contains__(self, value):
...             return any(v == value for v in self)
... 
>>> timeit.timeit('500 in x', setup='from __main__ import B; x = B(range(1000))', number=10000)
2.05952100000286
History
Date User Action Args
2014-09-19 20:57:15serhiy.storchakasetrecipients: + serhiy.storchaka, cool-RR
2014-09-19 20:57:15serhiy.storchakasetmessageid: <1411160235.21.0.465068413045.issue22446@psf.upfronthosting.co.za>
2014-09-19 20:57:15serhiy.storchakalinkissue22446 messages
2014-09-19 20:57:15serhiy.storchakacreate