Raymond Hettinger <[email protected]> added the comment:
Here's what I propose to add:
def total(self):
return sum(self.values())
def scaled_by(self, factor):
return Counter({elem : count * factor for elem, count in self.items()})
def scaled_to(self, target_total=1.0):
ratio = target_total / self.total()
return self.scaled_by(ratio)
These cover the common cases and they don't mutate the counter.
----------
versions: +Python 3.10 -Python 3.8
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue25478>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com