list.count() with no arguments

Johan Hahn johahn2003 at home.se
Sun Mar 27 10:23:35 EST 2005


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





More information about the Python-list mailing list