| t | import collections | t | import collections |
| | | |
| class DefCounter(collections.Counter): | | class DefCounter(collections.Counter): |
| | | |
| def __init__(self, iterable=None, /, **kwargs): | | def __init__(self, iterable=None, /, **kwargs): |
| self.missing = kwargs.pop('missing', -1) | | self.missing = kwargs.pop('missing', -1) |
| super().__init__(iterable, **kwargs) | | super().__init__(iterable, **kwargs) |
| | | |
| def __missing__(self, key): | | def __missing__(self, key): |
| return self.missing | | return self.missing |
| | | |
| 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)) |
| | | |
| def total(self): | | def total(self): |
| return sum(self.values()) | | return sum(self.values()) |