Wolfgang Maier added the comment:

????

I don't even know where to start with this.

a) this recipe is not working
b) it's hardly readable
c) it is pointless

Why are you complicating things by testing for != ?
What advantage does this offer over == ?

You do not need class methods at all to achieve what you want (in fact the 
__ne__ as a method of the container is just wrong), instead use the one-liner:

any(element == value for element in container)

to find out if any element of your container equals value without doing the 
identity check, but then:
the identity check is anyway the fast part compared to the equality check (at 
least you assumed that in your first post).

and in fact with:
>>> l=list(range(20000000))

>>> 20000000 in l
False

is much faster than:

>>> any(e == 20000000 for e in l)
False

despite checking identity AND equality, simply because it isn't doing things in 
Python.

So while the current docs say this about the in operator:

"""
For container types such as list, tuple, set, frozenset, dict, or 
collections.deque, the expression x in y is equivalent to any(x is e or x == e 
for e in y).
"""

I guess, that doesn't mean it is actually implemented like that, but only that 
the result is equivalent.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue21234>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to