Comparing dictionaries, is this valid Python?

François Pinard pinard at iro.umontreal.ca
Tue Dec 13 19:17:16 EST 2005


Hi, people.

I noticed today that dictionaries seem to support `==' comparison.  
(Retrospectively, it is strange that I never needed it before! :-)
Yet, before relying on this, I seeked for confirmation in the Python 
manuals, and did not succeed in finding it.  In particular:

   http://www.python.org/doc/2.3.5/lib/typesmapping.html

is silent on the subject.  As for:

   http://www.python.org/doc/2.3.5/lib/comparisons.html

it only says "Comparison operations are supported by all objects", which 
is a little vague, and no promise that comparisons are meaningful (for 
example, one might wonder what would exactly mean the comparison of open 
files).  The node even says: "Two more operations with the same 
syntactic priority, "in" and "not in", are supported only by sequence 
types (below).", which suggests that the information might not be fully
up-to-date, at least regarding dictionaries.

Would someone know where I could find a confirmation that comparing 
dictionaries with `==' has the meaning one would expect (even this is 
debatable!), that is, same set of keys, and for each key, same values?

-- 
François Pinard   http://pinard.progiciels-bpi.ca



More information about the Python-list mailing list