Author rhettinger
Recipients Allen Downey, DavidMertz, josh.r, mark.dickinson, pitrou, rhettinger, serhiy.storchaka, steven.daprano, veky, wolma
Date 2020-12-20.20:44:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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 /
        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:05rhettingersetrecipients: + rhettinger, mark.dickinson, pitrou, steven.daprano, serhiy.storchaka, wolma, josh.r, veky, Allen Downey, DavidMertz
2020-12-20 20:44:05rhettingersetmessageid: <>
2020-12-20 20:44:05rhettingerlinkissue25478 messages
2020-12-20 20:44:05rhettingercreate