Created
May 28, 2022 13:28
Revisions
-
Pythonian created this gist
May 28, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ import string def read_file_content(filename): with open(filename, 'r') as f: text = f.read() return text def count_words(): text = read_file_content("./story.txt") words = [] d = {} for line in text: line = text.rstrip() line = text.translate( line.maketrans("", "", string.punctuation)) words = line.split(" ") for word in words: d[word] = 1 if not word in d else d[word] + 1 print(d) if __name__ == '__main__': count_words()