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