Using re:
import re context, m = 'some file to search or text', {} letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] for i in range(len(letters)): m[letters[i]] = len(re.findall('{0}'.format(letters[i]), context)) print '{0} -> {1}'.format(letters[i], m[letters[i]])
This is all the more elegant and clean with Counter. However.
user2567070
source share