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