f | from collections import Counter | f | from collections import Counter |
| | | |
| class DefCounter(Counter): | | class DefCounter(Counter): |
| | | |
n | def __init__(self, iterable=None, missing=-1, **kwargs): | n | def __init__(self, seq=None, missing=-1, **kwargs): |
| super().__init__(iterable, **kwargs) | | super().__init__(seq, **kwargs) |
| 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([i for i in self.values() if i > 0]) | t | return sum((v for v in self.values() if v > 0)) |