Rich Comparisons Gotcha
Rhamphoryncus
rhamph at gmail.com
Tue Dec 9 14:34:31 EST 2008
You grossly overvalue using the "in" operator on lists. It's far more
common to use a dict or set for containment tests, due to O(1)
performance rather than O(n). I doubt the numpy array supports
hashing, so an error for misuse is all you should expect.
In the rare case that you want to test for identity in a list, you can
easily write your own function to do it upfront:
def idcontains(seq, obj):
for i in seq:
if i is obj:
return True
return False
More information about the Python-list
mailing list