Skip to content

Instantly share code, notes, and snippets.

@JSpiner
Created January 26, 2017 11:31
Show Gist options
  • Save JSpiner/ddb42da2e1ab6bae35c7b499a7801da4 to your computer and use it in GitHub Desktop.
Save JSpiner/ddb42da2e1ab6bae35c7b499a7801da4 to your computer and use it in GitHub Desktop.
class DictDiffer(object):
def __init__(self, past_dict, current_dict):
self.current_dict, self.past_dict = current_dict, past_dict
self.set_current, self.set_past = set(current_dict.keys()), set(past_dict.keys())
self.intersect = self.set_current.intersection(self.set_past)
def added(self):
return self.set_current - self.intersect
def removed(self):
return self.set_past - self.intersect
def changed(self):
return set(o for o in self.intersect if self.past_dict[o] != self.current_dict[o])
def unchanged(self):
return set(o for o in self.intersect if self.past_dict[o] == self.current_dict[o])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment