Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if Two Massive Python Dictionaries are Equivalent

I have a massive python dictionary with over 90,000 entries. For reasons I won't get into, I need to store this dictionary in my database and then at a later point recompile dictionary from the database entries.

I am trying to set up a procedure to verify that my storage and recompilation was faithful and that my new dictionary is equivalent to the old one. What is the best methodology for testing this.

There are minor differences and I want to figure out what they are.

like image 599
Spencer Avatar asked Sep 30 '11 14:09

Spencer


Video Answer


1 Answers

The most obvious approach is of course:

if oldDict != newDict:
  print "**Failure to rebuild, new dictionary is different from the old"

That ought to be the fastest possible, since it relies on Python's internals to do the comparison.

UPDATE: It seems you're not after "equal", but something weaker. I think you need to edit your question to make it clear what you consider "equivalent" to mean.

like image 100
unwind Avatar answered Oct 21 '22 21:10

unwind