def count_unique_word():
words = {}
st = string.whitespace + string.punctuation + string.digits + "\"'"
with open("./dataset/ihaveadream.txt", encoding='UTF-8') as file:
for line in file:
for word in line.lower().split():
word = word.strip(st)
words[word] = words.setdefault(word, 0) + 1
import string import sys
def count_unique_word(): words = {} st = string.whitespace + string.punctuation + string.digits + "\"'" with open("./dataset/ihaveadream.txt", encoding='UTF-8') as file:
for line in file: for word in line.lower().split(): word = word.strip(st) words[word] = words.setdefault(word, 0) + 1
dict_words=count_unique_word() dict_words
def majorityCnt(words): a=sorted(words.items(),key=lambda x:x[1], reverse=True) return a[0]
majorityCnt(dict_words)
import pickle with open("result.txt","wb") as f: pickle.dump(dict_words,f)
with open("result.txt","rb") as fin: data1=pickle.load(fin)
data1