[Python-ideas] collections.Counter should implement fromkeys
abedillon at gmail.com
Fri Jun 29 18:19:12 EDT 2018
> You need an iterable of the keys you're interested in to pass to the
> hypothetical ``fromkeys`` method. Why not iterate over that same iterable
> paired with zeros instead of passing it into ``fromkeys``?
Because, as in my original example code; the values could be zero or they
could be more, I just want to make sure the keys are in the counter when I
I'm not having any trouble finding a work around. I'm having trouble
understanding why I need to find a work around when Counter already
inherits from dict, dict.fromkeys is perfectly well defined, and there's
not really any other *obvious* best way to initialize the value for a set
Counter(dict.fromkeys(keys, value)) works just fine, but it feels wrong.
I'm using the copy-constructor because I know Counter is a subclass of dict.
I'm using fromkeys because I know how that class method works.
So why does the subclass lack functionality that the superclass has?
Because programmers wouldn't be able to wrap their heads around it?
I don't buy it. This feels like nanny-design trumping SOLID design
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas