<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1" />
<title>Strategy for determing difference between 2 very large dictionaries</title>
</head>
<body dir="ltr">
I'm looking for suggestions on the best ('Pythonic') way to determine the difference between 2 very large dictionaries containing simple key/value pairs.<br /><br />By difference, I mean a list of keys that are present in the first dictionary, but not the second. And vice versa. And a list of keys in common between the 2 dictionaries whose values are different.<br /><br />The 2 strategies I'm considering are:<br /><br />1. Brute force: Iterate through first dictionary's keys and determine which keys it has that are missing from the second dictionary. If keys match, then verify that the 2 dictionaries have identical values for the same key. Repeat this process for the second dictionary.<br /><br />2. Use sets: Create sets from each dictionary's list of keys and use Python's set methods to generate a list of keys present in one dictionary but not the other (for both dictionaries) as well as a set of keys the 2 dictionaries have in common. Using the set of keys in common, compare values across dictionaries to determine which keys have different values (can this last step be done via a simple list comprehension?)<br /><br />Feedback on my proposed strategies (or better strategies) would be greatly appreciated. <br /><br />Thank you,<br />Malcolm<br />
</body>
</html>