Jess Austin wrote:
> I'll go
> so far as to suggest that the existence of groupby() obviates the
> proposed tally().
Except that it requires building a list of values in
each group when all you want at the end is the length
of the list.
--
Greg
___
Pyth
Jess Austin wrote:
> Alex wrote:
>> On Apr 4, 2006, at 10:53 PM, Jess Austin wrote:
>>> Alex wrote:
import collections
def tally(seq):
d = collections.defaultdict(int)
for item in seq:
d[item] += 1
return dict(d)
[Jess again]
>>> def tally(seq):
Alex wrote:
> On Apr 4, 2006, at 10:53 PM, Jess Austin wrote:
> > Alex wrote:
> >> import collections
> >> def tally(seq):
> >> d = collections.defaultdict(int)
> >> for item in seq:
> >> d[item] += 1
> >> return dict(d)
> >
> > I'll stop lurking and submit the following:
>
On Apr 4, 2006, at 10:53 PM, Jess Austin wrote:
> Alex wrote:
>> import collections
>> def tally(seq):
>> d = collections.defaultdict(int)
>> for item in seq:
>> d[item] += 1
>> return dict(d)
>
> I'll stop lurking and submit the following:
>
> def tally(seq):
> return
Alex wrote:
> import collections
> def tally(seq):
> d = collections.defaultdict(int)
> for item in seq:
> d[item] += 1
> return dict(d)
I'll stop lurking and submit the following:
def tally(seq):
return dict((group[0], len(tuple(group[1])))
for group
On 4/4/06, Raymond Hettinger <[EMAIL PROTECTED]> wrote:
> [Alex]
> > This is quite general and simple at the same time: for example, it
> > was proposed originally to answer some complaint about any and all
> > giving no indication of the count of true/false items:
> >
> > tally(bool(x) for x in se
[Alex]
> This is quite general and simple at the same time: for example, it
> was proposed originally to answer some complaint about any and all
> giving no indication of the count of true/false items:
>
> tally(bool(x) for x in seq)
>
> would give a dict with two entries, counts of true and
Alex Martelli wrote:
> On Apr 4, 2006, at 8:01 AM, Jeremy Hylton wrote:
>
>> On 4/4/06, Alex Martelli <[EMAIL PROTECTED]> wrote:
>>> import collections
>>> def tally(seq):
>>> d = collections.defaultdict(int)
>>> for item in seq:
>>> d[item] += 1
>>> return dict(d)
> ..
Alex Martelli wrote:
> It's a bit late for 2.5, of course, but, I thought I'd propose it
> anyway -- I noticed it on c.l.py.
>
> In 2.3/2.4 we have many ways to generate and process iterators but
> few "accumulators" -- functions that accept an iterable and produce
> some kind of "summary re
On Apr 4, 2006, at 8:01 AM, Jeremy Hylton wrote:
> On 4/4/06, Alex Martelli <[EMAIL PROTECTED]> wrote:
>> import collections
>> def tally(seq):
>> d = collections.defaultdict(int)
>> for item in seq:
>> d[item] += 1
>> return dict(d)
...
> Putting it somewhere in colle
On 4/4/06, Alex Martelli <[EMAIL PROTECTED]> wrote:
> import collections
> def tally(seq):
> d = collections.defaultdict(int)
> for item in seq:
> d[item] += 1
> return dict(d)
>
> Nevertheless, simplicity and generality make it advisable to supply
> it as part of the standa
11 matches
Mail list logo