[issue1696199] Add collections.counts()

2009-01-12 Thread Raymond Hettinger
Raymond Hettinger rhettin...@users.sourceforge.net added the comment: Georg, could you give this a once over before I commit? Thanks. -- assignee: rhettinger - georg.brandl nosy: +georg.brandl Added file: http://bugs.python.org/file12695/counter5.diff

[issue1696199] Add collections.counts()

2009-01-12 Thread Georg Brandl
Georg Brandl ge...@python.org added the comment: Yes, I'll have a look this evening. ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1696199 ___ ___

[issue1696199] Add collections.counts()

2009-01-12 Thread Raymond Hettinger
Raymond Hettinger rhettin...@users.sourceforge.net added the comment: Attaching an update with improved docs. Thanks for looking at this. Added file: http://bugs.python.org/file12702/counter6.diff ___ Python tracker rep...@bugs.python.org

[issue1696199] Add collections.counts()

2009-01-12 Thread Amaury Forgeot d'Arc
Amaury Forgeot d'Arc amaur...@gmail.com added the comment: the typical usage is c=Counter(myseq) with no other non-dict accesses (mostly just c[elem]+=1 and print c[elem]) Isn't collections.defaultdict(lambda:0) enough for this purpose? -- nosy: +amaury.forgeotdarc

[issue1696199] Add collections.counts()

2009-01-12 Thread Steven Bethard
Steven Bethard steven.beth...@gmail.com added the comment: The whole point was to have a function (or class) that accumulates a sequence and counts it. collections.defaultdict(lambda: 0) doesn't achieve this on its own because it only knows how to handle sequences of (key, value): d =

[issue1696199] Add collections.counts()

2009-01-12 Thread Georg Brandl
Georg Brandl ge...@python.org added the comment: Attaching new patch with small changes: * Don't describe a class with Returns ... as if it was a function. * Indent interposed paragraphs so that the method descriptions still belong to the .. class directive. * Fixed Ned's typo. * Note that

[issue1696199] Add collections.counts()

2009-01-12 Thread Raymond Hettinger
Raymond Hettinger rhettin...@users.sourceforge.net added the comment: Thanks for the review comments. Incorporated all suggested changes and did some other minor tidying-up. Extended the update example to include c.update(Counter('abcdee')). Committed as r68559 . Decided to leave __repr__()

[issue1696199] Add collections.counts()

2009-01-09 Thread Raymond Hettinger
Raymond Hettinger rhettin...@users.sourceforge.net added the comment: Attaching an updated patch for Py2.7. * Kept OP's simple constructor call but renamed it from counts() to Counter(): item_counts = Counter('acabbacba') * Followed Guido's advice and avoided subclassing from

[issue1696199] Add collections.counts()

2009-01-09 Thread Raymond Hettinger
Raymond Hettinger rhettin...@users.sourceforge.net added the comment: Added a few more in-module tests. Added file: http://bugs.python.org/file12664/counter2.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1696199

[issue1696199] Add collections.counts()

2009-01-09 Thread Raymond Hettinger
Changes by Raymond Hettinger rhettin...@users.sourceforge.net: Removed file: http://bugs.python.org/file12662/counter.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1696199 ___

[issue1696199] Add collections.counts()

2009-01-09 Thread Raymond Hettinger
Changes by Raymond Hettinger rhettin...@users.sourceforge.net: Added file: http://bugs.python.org/file12665/counter3.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1696199 ___

[issue1696199] Add collections.counts()

2009-01-09 Thread Raymond Hettinger
Changes by Raymond Hettinger rhettin...@users.sourceforge.net: Removed file: http://bugs.python.org/file12664/counter2.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1696199 ___

[issue1696199] Add collections.counts()

2009-01-09 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: Some comments: - Counter sounds like a really strange name for a container. Why not call it Bag or Multiset (or CountingSet?) - why are the unittests inline rather than in Lib/test? inline tests don't get executed by the buildbots, nor by people

[issue1696199] Add collections.counts()

2009-01-09 Thread Raymond Hettinger
Raymond Hettinger rhettin...@users.sourceforge.net added the comment: The counts/counter moniker emerged from the python-dev discussion and I'm basically happy with it since the typical usage is c=Counter(myseq) with no other non-dict accesses (mostly just c[elem]+=1 and print c[elem]). It's a

[issue1696199] Add collections.counts()

2009-01-09 Thread Raymond Hettinger
Changes by Raymond Hettinger rhettin...@users.sourceforge.net: Added file: http://bugs.python.org/file12671/counter4.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1696199 ___