f | from collections import Counter | f | from collections import Counter |
| | | |
| class DefCounter(Counter): | | class DefCounter(Counter): |
| | | |
| def __init__(self, iterable=None, **kwargs): | | def __init__(self, iterable=None, **kwargs): |
n | self.missing = kwargs.pop('missing', -1) | n | self.missing_value = kwargs.pop('missing', -1) |
| super().__init__(iterable, **kwargs) | | 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)) |