dictionary comparison

Remco Gerlich scarblac-spamtrap at pino.selwerd.nl
Thu Aug 10 13:20:13 EDT 2000


Peter Schneider-Kamp wrote in comp.lang.python:
> pzs at dcs.gla.ac.uk wrote:
> > 
> > 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():
> 
> Far from being the best way, one obvious way would be to
> loop over the concatenated keys-sequence of both dicts:
> 
> for key in dict1.keys()+dict2.keys():
>   try:
>     if dict1[key] != < > == ... dict2[key]:
>       do something
>   except KeyError:
>     ...

Or use dict1 == dict2 :)

-- 
Remco Gerlich,  scarblac at pino.selwerd.nl
Hi! I'm a .sig virus! Join the fun and copy me into yours!



More information about the Python-list mailing list