Regular expressions are useful if you want to find complex patterns in a string. Since you want to count (as opposed to searching) simple (only individual alphabetic characters) "patterns", regular expressions are not a selection tool here.
If I understand correctly what you are trying, the most transparent way to solve this is to iterate over all the lines and iterate over all the characters in this line, and if this character is alphabetic, add 1 to the corresponding dictionary entry, In the code:
filename=raw_input() found = {} with open(filename) as file: for line in file: for character in line: if character in "abcdefghijklmnopqrstuvxyz":
After this loop went through the file, the dictionary found will contain the number of occurrences for each character.
source share