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.

Author anthony-flury
Recipients anthony-flury, docs@python
Date 2018-02-05.00:34:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1517790874.74.0.467229070634.issue32770@psf.upfronthosting.co.za>
In-reply-to
Content
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 ['red', 'blue', 'red', 'green', 'blue', 'blue']:
...     cnt[word] += 1
>>> cnt
Counter({'blue': 3, 'red': 2, 'green': 1})

clearly this could simply be : 

>>> # Tally occurrences of words in a list
>>> cnt = Counter(['red', 'blue', 'red', 'green', 'blue', 'blue'])
>>> cnt
Counter({'blue': 3, 'red': 2, 'green': 1})

(i.e. the iteration through the array is unneeded in this example).

The 2nd example is better in showing the 'entry-level' use of the Counter class.

There possibly does need to be a simple example of when you might manually increment the Counter class - but I don't think that the examples given illustrate that in a useful way; and I personally haven't come across a use-case for manually incrementing the Counter class entires that couldn't be accomplished with a comprehension or generator expression passed directly to the Counter constructor.
History
Date User Action Args
2018-02-05 00:34:34anthony-flurysetrecipients: + anthony-flury, docs@python
2018-02-05 00:34:34anthony-flurysetmessageid: <1517790874.74.0.467229070634.issue32770@psf.upfronthosting.co.za>
2018-02-05 00:34:34anthony-flurylinkissue32770 messages
2018-02-05 00:34:34anthony-flurycreate