Skip to content

Commit

Permalink
Add str() and repr() support to fancy dicts
Browse files Browse the repository at this point in the history
  • Loading branch information
HWoidt committed May 27, 2017
1 parent 20a2a7a commit 5e2e21d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions abrechnung/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def levenshtein(s1, s2):
return previous_row[-1]

class FuzzyDict:
def __init__(self, items=[]):
def __init__(self, items=[], threshold=5):
self.data = dict(items)
self.threshold = 5
self.threshold = threshold

def __setitem__(self, key, value):
self.data[key] = value
Expand All @@ -49,6 +49,12 @@ def __contains__(self, key):
def __iter__(self):
yield from self.data.values()

def __repr__(self):
return "FuzzyDict({data!r}, threshold={threshold})".format(**self.__dict__)

def __str__(self):
return str(self.data)

class NormalizingDict:
def __init__(self, items=[]):
self.data = {}
Expand All @@ -69,3 +75,9 @@ def normalize(self, key):

def __iter__(self):
yield from self.data.values()

def __repr__(self):
return "NormalizingDict({data!r})".format(**self.__dict__)

def __str__(self):
return str(self.data)

0 comments on commit 5e2e21d

Please sign in to comment.