The description of dictionary comparison was out of date. Rather than

try to explain the complex general scheme we actually use now, I decided
to spell out only what equality means (which is easy to explain and
intuitive), leaving the other outcomes unspecified beyond consistency.
This commit is contained in:
Tim Peters 2001-10-01 20:22:45 +00:00
parent 092a7a80fd
commit 20524dbf36
1 changed files with 12 additions and 9 deletions

View File

@ -815,13 +815,16 @@ Tuples and lists are compared lexicographically using comparison of
corresponding items. corresponding items.
\item \item
Mappings (dictionaries) are compared through lexicographic Mappings (dictionaries) compare equal if and only if their sorted
comparison of their sorted (key, value) lists.\footnote{ (key, value) lists compare equal.\footnote{The implementation computes
This is expensive since it requires sorting the keys first, this efficiently, without constructing lists or sorting.}
but it is about the only sensible definition. An earlier version of Outcomes other than equality are resolved consistently, but are not
Python compared dictionaries by identity only, but this caused otherwise defined.\footnote{Earlier versions of Python used\
surprises because people expected to be able to test a dictionary for lexicographic comparison of the sorted (key, value) lists, but this
emptiness by comparing it to \code{\{\}}.} was very expensive for the common case of comparing for equality. An
even earlier version of Python compared dictionaries by identity only,
but this caused surprises because people expected to be able to test
a dictionary for emptiness by comparing it to \code{\{\}}.}
\item \item
Most other types compare unequal unless they are the same object; Most other types compare unequal unless they are the same object;