f | from collections import Counter | f | from collections import Counter |
| | | |
| class DefCounter(Counter): | | class DefCounter(Counter): |
| | | |
n | def __init__(self, obj, missing=-1): | n | def __init__(self, iterable, missing=-1): |
| super().__init__(obj) | | super().__init__(iterable) |
| self.mis = missing | | self.missing = missing |
| | | |
| def __missing__(self, key): | | def __missing__(self, key): |
t | return self.mis | t | return self.missing |
| | | |
| def __abs__(self): | | def __abs__(self): |
| return sum([i for i in self.values() if i > 0]) | | return sum([i for i in self.values() if i > 0]) |