[Tutor] checksum of dictionary

Brad Reisfeld brad.reisfeld@colostate.edu
Wed Feb 12 09:32:51 2003


Hi,
I have a time-consuming function that operates on a large dictionary. Before
I call this function, I'd like to confirm that the dictionary has changed
since the last time I called the function.
To check for a change, I am thinking of calculating a checksum on the
dictionary.

My initial approach is something like

>>> import marshal
>>> import md5
>>> d={'a':1,'b':2}
>>> md5.new(marshal.dumps(d)).hexdigest()
'2854ff50b105cab3a4ca3d71c76834a7'
>>> d['c']=3
>>> md5.new(marshal.dumps(d)).hexdigest()
'8c3213334c7311d387aceb59610cfeff'
>>> del d['b']
>>> md5.new(marshal.dumps(d)).hexdigest()
'b9063f0f5409882e9a3474b70dc9d090'
>>> d['b']=3
>>> md5.new(marshal.dumps(d)).hexdigest()
'9af630eec20336c8842637893833baec'
>>> d['b']=2
>>> md5.new(marshal.dumps(d)).hexdigest()
'8c3213334c7311d387aceb59610cfeff'

Is a checksum a reasonable approach?
Is there a better or more economical way to check a large dictionary for
changes?

Thanks.

-Brad