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 | positive_sum = 0 | t | s = 0 |
| for count in self.values(): | | for i in self.values(): |
| if count > 0: | | if i > 0: |
| positive_sum += count | | s += i |
| return positive_sum | | return s |