issues with searching through dictionaries for certain values

Zentrader zentraders at
Fri Feb 1 16:28:29 CET 2008

On Feb 1, 6:27 am, "Connolly" <cho.hat... at> wrote:
> Hey,
> Right basically I've got to the end of my main section of my program an I've
> got it comparing the same dictionary to ensure that the values are the same
> (sounds stupid I know), yet what my line of code I am using to do this is
> failing to do is to check every single value. It is only checking the final
> value in my dictionary, if you require more info than this feel free to say
> but any help would be appreciated.
> Code in use is displayed below.
> f4 = files_stored[0]
> f5 = files_stored[0]
> for key in f4:
>     for items in f5:
>         if key == items:
>             f6 = {start+1: key}
>             final_dict.update(f6)
>         else:
>             print key, 'false'
> print final_dict

This is the same thing that I think you want to do.  Also, you never
increment the start variable so it always remains the same (i.e.
dictionary will only have one key), and the f6 dictionary will only
contain the last test anyway since you create a new dictionary on each
pass instead of adding to an existing dictionary.  Don't know if that
is intentional or not.
set_f4 = set(f4.keys())
set_f5 = set(f5.keys())
print set_f4.difference(set_f5)

More information about the Python-list mailing list