list.count() with no arguments

J

Johan Hahn

Wouldn't it be nice if list.count, called without any arguments,
returned a dict with the list's unique items as keys and their
frequency of occurance as values?
[1,2,1,'a'].count() {'a': 1, 1: 2, 2: 1}
'hello world'.count()
{' ': 1, 'e': 1, 'd': 1, 'h': 1, 'l': 3, 'o': 2, 'r': 1, 'w': 1}

....johahn
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Johan said:
Wouldn't it be nice if list.count, called without any arguments,
returned a dict with the list's unique items as keys and their
frequency of occurance as values?

No. It would require all sequences to support this protocol, which
would be tedious to implement. Some day, we may have a bag type,
so it would be better if this type supported frequency counting.

Regards,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top