f | from collections import Counter | f | from collections import Counter |
| | | |
| class DefCounter(Counter): | | class DefCounter(Counter): |
| | | |
n | def __init__(self, iterable=None, **args): | n | def __init__(self, iterable=None, **kwds): |
| self.missing = args.pop('missing', -1) | | self.missing = kwds.pop('missing', -1) |
| super().__init__(iterable, **args) | | super().__init__(iterable, **kwds) |
| | | |
| def __getitem__(self, key): | | def __getitem__(self, key): |
| return self.get(key, self.missing) | | return self.get(key, self.missing) |
| | | |
| def __abs__(self): | | def __abs__(self): |
t | return sum((value for value in self.values() if value > 0)) | t | return sum((v for v in self.values() if v > 0)) |