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