By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,941 Members | 1,753 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,941 IT Pros & Developers. It's quick & easy.

list.count() with no arguments

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Johan Hahn wrote:
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
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.