Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 20524db

Browse files
committed
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.
1 parent 092a7a8 commit 20524db

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

Doc/ref/ref5.tex

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@ \subsection{List displays\label{lists}}
191191
evaluated from left to right and placed into the list object in that
192192
order. When a list comprehension is supplied, it consists of a
193193
single expression followed by at least one \keyword{for} clause and zero or
194-
more \keyword{for} or \keyword{if} clauses. In this
194+
more \keyword{for} or \keyword{if} clauses. In this
195195
case, the elements of the new list are those that would be produced
196196
by considering each of the \keyword{for} or \keyword{if} clauses a block,
197-
nesting from
197+
nesting from
198198
left to right, and evaluating the expression to produce a list element
199199
each time the innermost block is reached.
200200
\obindex{list}
@@ -815,13 +815,16 @@ \section{Comparisons\label{comparisons}}
815815
corresponding items.
816816
817817
\item
818-
Mappings (dictionaries) are compared through lexicographic
819-
comparison of their sorted (key, value) lists.\footnote{
820-
This is expensive since it requires sorting the keys first,
821-
but it is about the only sensible definition. An earlier version of
822-
Python compared dictionaries by identity only, but this caused
823-
surprises because people expected to be able to test a dictionary for
824-
emptiness by comparing it to \code{\{\}}.}
818+
Mappings (dictionaries) compare equal if and only if their sorted
819+
(key, value) lists compare equal.\footnote{The implementation computes
820+
this efficiently, without constructing lists or sorting.}
821+
Outcomes other than equality are resolved consistently, but are not
822+
otherwise defined.\footnote{Earlier versions of Python used\
823+
lexicographic comparison of the sorted (key, value) lists, but this
824+
was very expensive for the common case of comparing for equality. An
825+
even earlier version of Python compared dictionaries by identity only,
826+
but this caused surprises because people expected to be able to test
827+
a dictionary for emptiness by comparing it to \code{\{\}}.}
825828
826829
\item
827830
Most other types compare unequal unless they are the same object;

0 commit comments

Comments
 (0)