[docs] [issue32770] collections.counter examples are misleading

Cheryl Sabella report at bugs.python.org
Mon Feb 5 21:21:09 EST 2018


Cheryl Sabella <chekat2 at gmail.com> 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 Raymond said above about Counters (that the core ability is to write c['x'] += 1 without a KeyError).  So, thanks to this report, I learned that today!

One thing that did surprise me in the example is that I expected the repr to be in insertion order in 3.7.  The class description says 'It is an unordered collection where elements are stored as dictionary keys' and I was wondering if that was still true since dicts now have a guaranteed order.  I tried it on the example, which still printed Counter({'blue': 3, 'red': 2, 'green': 1})!  Of course it makes sense after looking at the code because it calls `most_common` in the repr, but I hadn't realized that before.  So, two things learned about Counter today.   :-)

Anyway, writing this here to ask about the wording regarding 'unordered collection'.

Thanks!

----------
nosy: +csabella

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32770>
_______________________________________


More information about the docs mailing list