dictionary comparison

David Bolen db3l at fitlinxx.com
Thu Aug 10 13:29:50 EDT 2000


pzs at dcs.gla.ac.uk writes:

> I know this is going to be newbie-type question, so I apologise in
> advance.
> 
> What's the best way of comparing a dictionary with another (possibly
> itself) without doing each comparison twice as

You should be able to compare dictionary objects using the normal
operators (e.g., ==, <, > and so on).  For operations such as < or >,
the result will be based on the comparison of the smallest key
representing the first difference in the dictionary.

Keys and values within the dictionary are themselves compared with
general object comparisons, so if you are using your own classes as
keys or values you want to make sure that they themselves compare
properly (either via the default behavior or locally implemented
__cmp__)

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list