[Python-ideas] Fwd: collections.Counter should implement fromkeys
tim.peters at gmail.com
Fri Jun 29 22:51:38 EDT 2018
Note to repliers to Abe (and others recently): replies to Google Groups
posts are broken for now on this list, so be sure to replace
python-ideas at googlegroups.com
python-ideas at python.org
in your reply. Else the mailing list (neither Google Groups nor the
python.org archive) won't get it.
>> So, e.g., someone will be unpleasantly surprised no matter what
> Sure, but in Hettinger's own words
<https://www.youtube.com/watch?v=HTLu2DFOdTg&t=24m46s> "whenever you have a
> everyone should get their wish". People that want a counting constructor
> have that,people that want the ability to initialize values don't have
I think the missing bit here is that there weren't any "constructor wars"
for Counter. In all this time, I don't believe I've heard anyone say they
wanted a Counter.fromkeys() before. For that matter, I'd bet a dollar that
most Python programmers don't know that dict.fromkeys() exists, despite
that it was added in Python 2.3.
As I recall, the primary motivation for adding dict.fromkeys() was to make
using dicts to mimic sets a little easier, by providing a constructor that
threw away duplicates and didn't really care about the values (so no value
was required, and nobody cared that it defaulted to the _seemingly_ insane
`None` - using `None` values for sets-implemented-as-dicts was a de facto
informal standard at the time).
But one release later (2.4) a set type was added too, so the primary
motivation for fromkeys() went away.
15 years later you're jumping up & down about Counter.fromkeys() not being
there, and that's why nobody much cares ;-)
> I'm tempted to indulge in the meta argument which you're obviously
> striving to avoid,
And succeeding! I can't be sucked into it :-) FWIW, fine by me if
Counter.fromkeys() is added, doing exactly what you want. Raymond may have
a different judgment about that, though. I don't believe he reads
python-ideas anymore, so opening an enhancement request on bugs.python.org
is the way to get his attention.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas