Sreenivas Reddy Thatiparthy writes:
> How about this one liner, if you prefer them;
> set([(k,yourList.count(k)) for k in yourList])
That has a rather bad efficiency problem if the list is large.
--
http://mail.python.org/mailman/listinfo/python-list
On Jun 4, 11:14 am, kj wrote:
> Task: given a list, produce a tally of all the distinct items in
> the list (for some suitable notion of "distinct").
>
> Example: if the list is ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b',
> 'c', 'a'], then the desired tally would look something like this:
>
> [('a',
Thank you all!
~K
--
http://mail.python.org/mailman/listinfo/python-list
On 06/05/10 04:38, Magdoll wrote:
> On Jun 4, 11:33 am, Peter Otten <__pete...@web.de> wrote:
>> kj wrote:
>>
>>> Task: given a list, produce a tally of all the distinct items in
>>> the list (for some suitable notion of "distinct").
>>
>>> Example: if the list is ['a', 'b', 'c', 'a', 'b', 'c', 'a'
kj wrote:
Task: given a list, produce a tally of all the distinct items in
the list (for some suitable notion of "distinct").
Example: if the list is ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b',
'c', 'a'], then the desired tally would look something like this:
[('a', 4), ('b', 3), ('c', 3)]
I
On Jun 4, 11:33 am, Peter Otten <__pete...@web.de> wrote:
> kj wrote:
>
> > Task: given a list, produce a tally of all the distinct items in
> > the list (for some suitable notion of "distinct").
>
> > Example: if the list is ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b',
> > 'c', 'a'], then the desired
On Jun 4, 11:28 am, Paul Rubin wrote:
> kj writes:
> > 1. is there a standard name for it?
>
> I don't know of one, or a stdlib for it, but it's pretty trivial.
>
> > def tally(c):
> > t = dict()
> > for x in c:
> > t[x] = t.get(x, 0) + 1
> > return sorted(t.items(), key=lambd
kj wrote:
>
>
>
>
>
> Task: given a list, produce a tally of all the distinct items in
> the list (for some suitable notion of "distinct").
>
> Example: if the list is ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b',
> 'c', 'a'], then the desired tally would look something like this:
>
> [('a', 4),
kj writes:
> 1. is there a standard name for it?
I don't know of one, or a stdlib for it, but it's pretty trivial.
> def tally(c):
> t = dict()
> for x in c:
> t[x] = t.get(x, 0) + 1
> return sorted(t.items(), key=lambda x: (-x[1], x[0]))
I like to use defaultdict and tuple