f | from collections import Counter | f | from collections import Counter |
| | | |
| class DefCounter(Counter): | | class DefCounter(Counter): |
| | | |
n | def __init__(self, iterable=None, /, missing=-1, **kwds): | n | def __init__(self, iterable=None, missing=-1, **kwds): |
| self.missing = missing | | self.missing = missing |
| super().__init__(iterable, **kwds) | | super().__init__(iterable, **kwds) |
| | | |
| def __missing__(self, key): | | def __missing__(self, key): |
| return self.missing | | return self.missing |
| | | |
| def __abs__(self): | | def __abs__(self): |
t | return sum((elem for elem in self.values() if elem > 0)) | t | return sum((x for x in self.values() if x > 0)) |