[Python-ideas] Make max() stable

Chris Angelico rosuav at gmail.com
Tue Jan 21 22:21:50 CET 2014


On Wed, Jan 22, 2014 at 8:11 AM, David Mertz <mertz at gnosis.cx> wrote:
> But this is just a question of inequality versus identity and that sets and
> dictionaries are, IMO, too sloppy about that.  That is, they behave exactly
> as documented and as the BDFL has decreed, but I still feel uneasy about:
>
>   >>> a = {1, 1+0j, 2}
>   >>> b = {1+0j, 1, 2}
>   >>> a
>   {(1+0j), 2}
>   >>> b
>   {1, 2}
>   >>> a == b
>   True

This is because Python's made the decision that an int, a float, and a
complex, representing the same number, should compare equal. I
personally think they shouldn't (partly because it implies that
they're all in some sort of tower, where the higher types can
represent the lower types perfectly, and can perfectly represent that
there's no further information - true of (float, complex) but not of
(int, float), and it leads to problems with large integers), but it's
a decision that's been made, and sets/dicts have to follow that. With
small numbers, it just means that there's an identity-vs-value
distinction (1 == 1.0 == 1+0j, but they're not is-identical), and sets
have always had and will always have that issue.

ChrisA


More information about the Python-ideas mailing list