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.

classification
Title: collections.Counter support multiplication
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.9, Python 3.8, Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Consider adding a normalize() method to collections.Counter()
View: 25478
Assigned To: Nosy List: Dominick Johnson, ammar2, rhettinger
Priority: normal Keywords:

Created on 2020-01-23 18:12 by Dominick Johnson, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg360573 - (view) Author: Dominick Johnson (Dominick Johnson) Date: 2020-01-23 18:12
I would love to see collections.Counter support scalar multiplication.

## My Use Case:

I am writing a python script to manage hardware selections for custom-build computers. Users are able to select various options from a web interface, and the script compiles a list of parts that need purchased.

Each option for user selection has a corresponding Counter object to keep track of what parts are needed for that selection. For example, the user option "i5 Processor" would have a corresponding counter that might looks roughly like this: {"i5-xxxx": 1, "xxxxx Motherboard"}. A user option for "2 TB RAID 10" might have {"1 TB HDD": 4}.

The script adds all the counters for the selected options together to produce a counter detailing the full parts list for the build.

I'd like to add a feature to the script that allows the user to also specify a quantity for certain selections. (Maybe the user wants 2 1TB Storage Drives without any kind of RAID setup). It would be really convenient to be able to simply multiply the selection's counter by it's quantity before adding it to the main counter. e.g. `main_counter += secondary_counter * selection_quantity`

This seems like an extremely simple feature to add, and I would of course be willing to add it myself as long as the Python team is willing to accept a pull request from me adding this feature. However, I've never contributed to such a large project before, so I'm not sure what kind of procedures are in place to make it happen.
msg360577 - (view) Author: Ammar Askar (ammar2) * (Python committer) Date: 2020-01-23 20:21
Duplicate of https://bugs.python.org/issue25478

See Raymond's open PR here: https://github.com/python/cpython/pull/6574
History
Date User Action Args
2022-04-11 14:59:25adminsetgithub: 83618
2020-01-23 20:21:35ammar2setstatus: open -> closed

superseder: Consider adding a normalize() method to collections.Counter()

nosy: + ammar2
messages: + msg360577
resolution: duplicate
stage: resolved
2020-01-23 18:42:53xtreaksetnosy: + rhettinger
2020-01-23 18:12:47Dominick Johnsoncreate