[docs] [issue33572] Better document mixed-type comparison of set items, dict keys

Terry J. Reedy report at bugs.python.org
Fri May 18 15:44:10 EDT 2018


Terry J. Reedy <tjreedy at udel.edu> added the comment:

With Tim's addition

>>> from fractions import Fraction as F
>>> from decimal import Decimal as D
>>> s = {0, 1, 0.0, 1.0, F(0,1), F(1, 1), D(0), D(1), False, True}
>>> s
{0, 1}

I think we should consider moving the main discussion of the general comparison and hashing principle and example to the set entry.  (Sets ars simpler and are when people new to Python already know about.) Point out that for displays, the first of equals is kept and not replaced (this is also true of dicts).  Then, in the dict entry, say that dict keys are treated like set items, give an equivalent dict example, and link to the discussion of set items.

>>> x = None
>>> d = {0:x, 1:x, 0.0:x, 1.0:x, F(0,1):x, F(1, 1):x, D(0):x, D(1):x, False:x, True:x}
>>> d
{0: None, 1: None}
>>>

----------
title: False/True as dictionary keys treated as integers -> Better document mixed-type comparison of set items, dict keys

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33572>
_______________________________________


More information about the docs mailing list