Comparing float and decimal

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Sep 30 04:42:20 CEST 2008


En Thu, 25 Sep 2008 08:02:49 -0300, Mark Dickinson <dickinsm at gmail.com>  
escribió:
> 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

Ouch!

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

And I was thinking all this thread was just a theoretical question without  
practical consequences...

-- 
Gabriel Genellina




More information about the Python-list mailing list