compare dictionary values
Tim Williams (gmail)
tdwdotnet at gmail.com
Fri Dec 30 22:58:49 CET 2005
In <dp4124$pki$1 at solaris.cc.vt.edu>, 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.
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:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list