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