dictionary comparison

Alex Martelli alex at magenta.com
Thu Aug 10 16:07:23 EDT 2000


<pzs at dcs.gla.ac.uk> wrote in message news:8muih7$om6$1 at nnrp1.deja.com...
> 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
>
> for key1 in dict1.keys():
> for key2 in dict2.keys():

What sort of comparison do you require?  If it's just equality,
as was already indicated, dict1==dict2 will work -- but if what
you want to check is, say, whether the set of keys are the
same (independently of what value corresponds to each key),
or other kinds of comparison, it won't do.  I can't tell from
these two non-nested empty (syntactically invalid) loops
what it is that you mean to do...


Alex






More information about the Python-list mailing list