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 rhettinger
Recipients anthony-flury, docs@python, rhettinger
Date 2018-02-05.04:36:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1517805376.67.0.467229070634.issue32770@psf.upfronthosting.co.za>
In-reply-to
Content
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() builtin- where the core ability is to write s.append(e) and there is a convenience of calling list(iterable).

Another reason the first example goes first because it is simple.  It shows counting in isolation with no other distractions (an in-vitro example).

The second example is in a more complex environment incorporating file access and regular expressions (an in-vivo example).

FWIW, there are plenty of examples of using the += style.  Here's one I use in my Python courses:

    'Scan a log file from a NASA server'

    import collections, re, pprint

    visited = collections.Counter()
    with open('notes/nasa_19950801.log') as f:
        for line in f:
            mo = re.search(r'GET\s+(\S+)\s+200', line)
            if mo is not None:
                url = mo.group(1)
                visited[url] += 1

    pprint.pprint(visited.most_common(20))

I've had good luck with people understanding the docs as-is, so I'm going to decline the suggestion.  I do appreciate you taking the time to share your thoughts.
History
Date User Action Args
2018-02-05 04:36:16rhettingersetrecipients: + rhettinger, docs@python, anthony-flury
2018-02-05 04:36:16rhettingersetmessageid: <1517805376.67.0.467229070634.issue32770@psf.upfronthosting.co.za>
2018-02-05 04:36:16rhettingerlinkissue32770 messages
2018-02-05 04:36:15rhettingercreate