Message383447
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. |
|
Date |
User |
Action |
Args |
2020-12-20 20:44:05 | rhettinger | set | recipients:
+ rhettinger, mark.dickinson, pitrou, steven.daprano, serhiy.storchaka, wolma, josh.r, veky, Allen Downey, DavidMertz |
2020-12-20 20:44:05 | rhettinger | set | messageid: <1608497045.86.0.0501068788391.issue25478@roundup.psfhosted.org> |
2020-12-20 20:44:05 | rhettinger | link | issue25478 messages |
2020-12-20 20:44:05 | rhettinger | create | |
|