comparing dictionaries

cokofreedom at gmail.com cokofreedom at gmail.com
Wed May 7 10:15:48 EDT 2008


On May 7, 4:08 pm, brad <byte8b... at gmail.com> wrote:
> 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

Well

for k, v in first_dict.items():
  if k not in second_dict or k in second_dict and k[v] !=
second_dict[k]:
    let you know?



More information about the Python-list mailing list