f | from collections import Counter | f | from collections import Counter |
| | | |
| class DefCounter(Counter): | | class DefCounter(Counter): |
| | | |
| def __init__(self, iterable=None, missing=-1): | | def __init__(self, iterable=None, missing=-1): |
| super().__init__(iterable) | | super().__init__(iterable) |
| self.missing = missing | | self.missing = missing |
| | | |
| def __missing__(self, key): | | def __missing__(self, key): |
| return self.missing | | return self.missing |
| | | |
| def __abs__(self): | | def __abs__(self): |
t | s = 0 | t | positive_sum = 0 |
| for i in self.values(): | | for count in self.values(): |
| if i > 0: | | if count > 0: |
| s += i | | positive_sum += count |
| return s | | return positive_sum |