comparing dictionaries
Terry Reedy
tjreedy at udel.edu
Thu May 8 16:42:10 EDT 2008
"Miki" <miki.tebeka at gmail.com> wrote in message
news:ad2861dc-d9fd-4ad4-aa3d-1e401e581cab at b9g2000prh.googlegroups.com...
Hello,
> I want to compare two dicts that should have identical info just in a
> different data structure. The first dict's contents look like this. It
> is authoritative... I know for sure it has the correct key value pairs:
>
> {'001' : '01'}
>
> The second dict's contents are like this with a tuple instead of a
> string for the key:
>
> {('This is one', '001'): '01'}
>
> Pseudo Code:
> for key, value in first_dict.iteritems():
> # How do I do the following line?
> if key not in second_dict or if it is, but has has the wrong value,
> then let me know
Does this work for you?
for key,value in second_dict.iteritems():
try:
if first_dict[key(1)] == value:
return True
else:
return False:
except KeyError:
return False
tjr
More information about the Python-list
mailing list