This way creates a dictionary histogram for each character, which could be used to create a bar chart or similar. If you want to limit it to letters or some subset, you'll need to add an extra conditional, or filter freqs
at the end.
freqs = {}
with open('your_filename.txt') as f:
for line in f:
for char in line:
if char in freqs:
freqs[char] += 1
else:
freqs[char] = 1
print(freqs)
You can also write the same logic using dict.setdefault:
freqs = {}
with open('your_filename.txt') as f:
for line in f:
for char in line:
freqs.setdefault(char, 0)
freqs[char] += 1
Or using collections.defaultdict:
from collections import defaultdict
freqs = defaultdict(int)
with open('your_filename.txt') as f:
for line in f:
for char in line:
freqs[char] += 1