f | from collections import Counter | f | from collections import Counter |
| | | |
| class DefCounter(Counter): | | class DefCounter(Counter): |
| | | |
n | def __init__(self, iterable=None, **kwds): | n | def __init__(self, iterable=None, **kwargs): |
| self.missing = kwds.pop('missing', -1) | | self.missing_value = kwargs.pop('missing', -1) |
| super().__init__(iterable, **kwds) | | super().__init__(iterable, **kwargs) |
| | | |
| def __missing__(self, key): | | def __missing__(self, key): |
t | return self.missing | t | return self.missing_value |
| | | |
| def __abs__(self): | | def __abs__(self): |
| return sum((value for value in self.values() if value > 0)) | | return sum((value for value in self.values() if value > 0)) |