[Python-Dev] Getting values stored inside sets (original) (raw)

Steven D'Aprano steve at pearwood.info
Fri Apr 3 17:41:25 CEST 2009


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] indicesofoddnumbers = [alist.index(n) for n in alist if n%2] if Decimal('3') in indicesofoddnumbers: ... print alist[Decimal('3')] ... Traceback (most recent call last): File "", line 2, in 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



More information about the Python-Dev mailing list