This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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 <1608497045.86.0.0501068788391.issue25478@roundup.psfhosted.org>
In-reply-to
Content
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.
History
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: <1608497045.86.0.0501068788391.issue25478@roundup.psfhosted.org>
2020-12-20 20:44:05rhettingerlinkissue25478 messages
2020-12-20 20:44:05rhettingercreate