Re: [Python-Dev] function for counting items in a sequence

2007-04-09 Thread Delaney, Timothy (Tim)
Greg Ewing wrote: > Steven Bethard wrote: > >> * Greg Ewing - counteach(), countall() >> * Guido - counts() is fine > > I'm happy with counts() too -- I only suggested the > others in case counts() wasn't acceptable for some > reason. If Guido likes it, that's good enough for > me. I think I'd

Re: [Python-Dev] function for counting items in a sequence

2007-04-08 Thread Greg Ewing
Steven Bethard wrote: > * Greg Ewing - counteach(), countall() > * Guido - counts() is fine I'm happy with counts() too -- I only suggested the others in case counts() wasn't acceptable for some reason. If Guido likes it, that's good enough for me. -- Greg ___

Re: [Python-Dev] function for counting items in a sequence

2007-04-08 Thread Greg Ewing
Raymond Hettinger wrote: > Instead of a separate function in collections, it may be sensible to stick > with > the familiar and provide a dictionary contructor for the commonly encounter > use > case of counting things: I don't think that's a good idea. The dict class should restrict itself to b

Re: [Python-Dev] function for counting items in a sequence

2007-04-08 Thread Guido van Rossum
On 4/8/07, Georg Brandl <[EMAIL PROTECTED]> wrote: > I can live with counts(), though I always ask myself "who counts?" ;) The Count, of course. :-) -- --Guido van Rossum (home page: http://www.python.org/~guido/) ___ Python-Dev mailing list Python-D

Re: [Python-Dev] function for counting items in a sequence

2007-04-08 Thread Georg Brandl
Steven Bethard schrieb: > A summary response to the issues raised so far... > > On what the name should be: > * Adam Olsen - countunique(), countdistinct(), countduplicates() > * Greg Ewing - counteach(), countall() > * Kevin Jacobs - tally() > * Guido - counts() is fine > So I guess I'll stick wi

Re: [Python-Dev] function for counting items in a sequence

2007-04-08 Thread Steven Bethard
A summary response to the issues raised so far... On what the name should be: * Adam Olsen - countunique(), countdistinct(), countduplicates() * Greg Ewing - counteach(), countall() * Kevin Jacobs - tally() * Guido - counts() is fine So I guess I'll stick with counts(). On whether the count of a

Re: [Python-Dev] function for counting items in a sequence

2007-04-08 Thread Raymond Hettinger
Instead of a separate function in collections, it may be sensible to stick with the familiar and provide a dictionary contructor for the commonly encounter use case of counting things: @classmethod def fromcount(cls, iterable): d = cls() for elem in iterable: d[elem] = d.get(elem,

Re: [Python-Dev] function for counting items in a sequence

2007-04-07 Thread Kevin Jacobs <[EMAIL PROTECTED]>
On 4/7/07, Guido van Rossum <[EMAIL PROTECTED]> wrote: On 4/7/07, Adam Olsen <[EMAIL PROTECTED]> wrote: > On 4/7/07, Steven Bethard <[EMAIL PROTECTED]> wrote: > > Here's a patch implementing collections.counts() as suggested above: > > The name doesn't make it obvious to me what's going on. May

Re: [Python-Dev] function for counting items in a sequence

2007-04-07 Thread Guido van Rossum
On 4/7/07, Adam Olsen <[EMAIL PROTECTED]> wrote: > On 4/7/07, Steven Bethard <[EMAIL PROTECTED]> wrote: > > Here's a patch implementing collections.counts() as suggested above: > > The name doesn't make it obvious to me what's going on. Maybe > countunique()? Some other options are countdistinct(

Re: [Python-Dev] function for counting items in a sequence

2007-04-07 Thread Greg Ewing
Adam Olsen wrote: > The name doesn't make it obvious to me what's going on. Maybe > countunique()? That doesn't sound any more obvious to me. counteach? countall? -- Greg ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailma

Re: [Python-Dev] function for counting items in a sequence

2007-04-07 Thread Greg Ewing
Steven Bethard wrote: > Guido commented in the tracker that it would be worth discussing > whether that last item (``item_counts['d']``) should return 0 (as a > defaultdict would) or raise KeyError (as a dict would). If you've asked for a count of 'd's, and there aren't any 'd's, the most sensible

Re: [Python-Dev] function for counting items in a sequence

2007-04-07 Thread Brett Cannon
On 4/7/07, Steven Bethard <[EMAIL PROTECTED]> wrote: On 4/7/07, Steven Bethard <[EMAIL PROTECTED]> wrote: > Here's a patch implementing collections.counts() as suggested above: > > http://bugs.python.org/1696199 > > Example usage, from the docstring:: > > >>> items = 'acabbacba' >

Re: [Python-Dev] function for counting items in a sequence

2007-04-07 Thread Adam Olsen
On 4/7/07, Steven Bethard <[EMAIL PROTECTED]> wrote: > Here's a patch implementing collections.counts() as suggested above: The name doesn't make it obvious to me what's going on. Maybe countunique()? Some other options are countdistinct() and countduplicates(). > >>> items = 'acabbacba'

Re: [Python-Dev] function for counting items in a sequence

2007-04-07 Thread Steven Bethard
On 4/7/07, Steven Bethard <[EMAIL PROTECTED]> wrote: > Here's a patch implementing collections.counts() as suggested above: > > http://bugs.python.org/1696199 > > Example usage, from the docstring:: > > >>> items = 'acabbacba' > >>> item_counts = counts(items) > >>> for item in

Re: [Python-Dev] function for counting items in a sequence

2007-04-07 Thread Steven Bethard
Alex Martelli wrote: > Steven Bethard <[EMAIL PROTECTED]> wrote: > >> Alex Martelli wrote: >> > If we had a "turn sequence into bag" function somewhere >> > (and it might be worth having it for other reasons): >> > >> > def bagit(seq): >> > import collections >> > d = collections.default