Anthony Flury added the comment:
Cheryl :
When you iterate around a counter instance it does return keys in the order
they are first encountered/inserted - so I agree with you that it is an ordered
collection from Python 3.7 onwards (although the iteration and the repr are
ordered in differe
Cheryl Sabella added the comment:
You know, I'm not sure if I had ever seen that example before. When you click
Counter at the top of the page, it goes right to the class definition, which is
past the example.
Having said that, I really like the example. Until now, I didn't realize what
Ra
Anthony Flury added the comment:
Raymond,
I completely understand your comment but I do disagree.
My view would be that the documentation of the stdlib should document the entry
level use cases.
The first example given uses nothing special from the Counter class - you could
implement exactly
Raymond Hettinger added the comment:
Thanks for the suggestion. I respectfully disagree. The "core" functionality
of Counter is the ability to write c['x'] += 1 without risking a KeyError. The
add-on capability is to process an entire iterable all at once. This is
analogous to the list()
New submission from Anthony Flury :
The first example given for collections.Counter is misleading - the
documentation ideally should show the 'best' (one and only one) way to do
something and the example is this :
>>> # Tally occurrences of words in a list
>>> cnt = Counter()
>>> for word in