infile = open("afile.txt")
count = {}
for aline in infile:
words = aline.split()
for word in words:
if word in count:
count[word] += 1
else:
count[word] = 1
print(count)
An other way this code also remove punctuation and covert to lower case.
from collections import Counter
with open('afile.txt') as f:
text = f.read().lower()
words = [c for c in text.split() if c.isalpha()]
print(Counter(words))