compare dictionary values

Tim Williams (gmail) tdwdotnet at
Fri Dec 30 22:58:49 CET 2005

In <dp4124$pki$1 at>, rbt wrote:

> > What's a good way to compare values in dictionaries?

Do you need to compare dictionaries, if its an option it would be
simpler/cheaper  to compare  each entry from your file listing with entries
in a single dict and act accordingly, mainly because you will already have
built your path/date pairs from your dir listing,  adding them to a dict
purely for comparison is an extra step.

import os

new_files = [ ]
changed = [ ]

listing = os.listdir('c:/python24')
for a_file in listing:
    f_date = os.path.getmtime(os.path.join('c:/python24' , a_file))
        if mydict[a_file] != f_date:
    mydict[a_file] = f_date

deleted = [ key for key in mydict if not key in listing ]

for x in deleted:
    del mydict[x]

print changed
print new_files
print deleted

HTH :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list