f | from collections import Counter | f | from collections import Counter |
| | | |
| class DefCounter(Counter): | | class DefCounter(Counter): |
| | | |
n | def __init__(self, data, missing=-1): | n | def __init__(self, collect, missing=-1): |
| super().__init__(data) | | super().__init__(collect) |
| 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 | sum = 0 | t | mod = 0 |
| for key, value in self.items(): | | for elem, count in self.items(): |
| if value > 0: | | if count > 0: |
| sum += value | | mod += count |
| return sum | | return mod |