So I have a list of words `wordList = list().\' Right now, I am counting each letter in each of the words throughout the whole list using this code
cnt = C
You can eliminate a for
with update
, which updates count from an iterable (in this case, a string):
from collections import Counter
words = 'happy harpy hasty'.split()
c=Counter()
for word in words:
c.update(set(word))
print c.most_common()
print [a[0] for a in c.most_common()]
[('a', 3), ('h', 3), ('y', 3), ('p', 2), ('s', 1), ('r', 1), ('t', 1)]
['a', 'h', 'y', 'p', 's', 'r', 't']