I am trying to read from a txt file and counts the number of times each word appears. The problem is that it counts the EOL characters as well. I tried to use the rstrip, still it didn't do anything. So how can I handle these end-of-line characters?
Please help.
Object= open('w.txt','r')
L= Object.read().rstrip()
occurrenences={}
for word in L.split():
occurrenences[word] = occurrenences.get(word,0)+1
for word in occurrenences:
print(occurrenences[word],word)
Object.close()