Popular recipes by Paul Bohm http://code.activestate.com/recipes/users/4173615/2010-04-18T05:52:57-07:00ActiveState Code RecipesList with fast membership test (__contains__) (Python)
2010-04-18T05:52:57-07:00Paul Bohmhttp://code.activestate.com/recipes/users/4173615/http://code.activestate.com/recipes/577185-list-with-fast-membership-test-__contains__/
<p style="color: grey">
Python
recipe 577185
by <a href="/recipes/users/4173615/">Paul Bohm</a>
(<a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/subclass/">subclass</a>).
Revision 3.
</p>
<p>Just a list subclass with a fast hash based __contains__ provided by a Set. Inheriting from list was far more work than I had anticipated AND the code below is still buggy.</p>
<p>Still, this provides O(1) indexed access and O(1) contains. If you use this expect the slicing code to be broken despite the attempts to get it right. Fixes graciously accepted!</p>