Count words in file

This commit is contained in:
lolabird 2023-11-19 16:24:06 -07:00
commit 8a69d379b9

View file

@ -1 +1,24 @@
open(alice_in_wonderland.txt, 'r')
aliceBook = open("thinkcspy/Chapter-12-Exercises/alice_in_wonderland.txt", "r")
aliceDict = {}
for line in aliceBook:
words = line.split()
for word in words:
word = word.lower()
newWord = ""
for char in word:
if char.isalpha():
newWord += char
word = newWord
if word not in aliceDict:
aliceDict[word] = 1
else:
aliceDict[word] += 1
print(aliceDict)
aliceBook.close()