With CPython this is probably the faster version, the version with list.count() has to be used only if you are sure to always have a short input list, because it's O(n^2):
str_list = ['StringA', 'StringC', 'StringB',
'StringA', 'StringC', 'StringD',
'StringA' ]
str_counts = {}
for s in str_list:
if s in str_counts:
str_counts[s] += 1
else:
str_counts[s] = 1
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
