Comparing float and decimal

Mark Dickinson dickinsm at gmail.com
Thu Sep 25 07:02:49 EDT 2008


On Sep 23, 1:58 pm, Robert Lehmann <stargam... at gmail.com> wrote:
> I don't see why transitivity should apply to Python objects in general.

Hmmm.  Lack of transitivity does produce some, um, interesting
results when playing with sets and dicts.  Here are sets s and
t such that the unions s | t and t | s have different sizes:

>>> from decimal import Decimal
>>> s = set([Decimal(2), 2.0])
>>> t = set([2])
>>> len(s | t)
2
>>> len(t | s)
1

This opens up some wonderful possibilities for hard-to-find bugs...

Mark



More information about the Python-list mailing list