On Sat, 4 Apr 2009 02:07:28 am Antoine Pitrou wrote: > Your example is wrong: Of course it is. The perils of posting at 2am, sorry. Nevertheless, the principle still holds. There's nothing in Python that prohibits two objects from being equal, but without them being interchangeable. As poorly written as my example was, it still holds: I just need to add a level of indirection. >>> alist = [100, 111, 102, 103, 105, 104, 106, 108] >>> indices_of_odd_numbers = [alist.index(n) for n in alist if n%2] >>> if Decimal('3') in indices_of_odd_numbers: ... print alist[Decimal('3')] ... Traceback (most recent call last): File "<stdin>", line 2, in <module> TypeError: list indices must be integers Python does not promise that if x == y, you can use y anywhere you can use x. Nor should it. Paul's declaration of abuse of __eq__ is unfounded. -- Steven D'Aprano
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4