f | from collections import Counter | f | from collections import Counter |
| | | |
| class DefCounter(Counter): | | class DefCounter(Counter): |
| | | |
n | def __init__(self, obj, missing=-1): | n | def __init__(self, iterable, missing=-1): |
| super().__init__(obj) | | 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 | res = 0 | t | summ = 0 |
| for val in self.values(): | | for value in self.values(): |
| if val > 0: | | if value > 0: |
| res += val | | summ += value |
| return res | | return summ |