From aceb1c3bedebf5c09fb7182ffca7c2abdc02f32d Mon Sep 17 00:00:00 2001 From: harshvardhan194 <69424785+harshvardhan194@users.noreply.github.com> Date: Mon, 5 Oct 2020 19:36:42 +0530 Subject: [PATCH] Create Most_occuring_word Program to find the most used word in a given txt file --- Most_occuring_word | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Most_occuring_word diff --git a/Most_occuring_word b/Most_occuring_word new file mode 100644 index 0000000..c09b217 --- /dev/null +++ b/Most_occuring_word @@ -0,0 +1,15 @@ +fname = input('Enter file name: ') +fhand = open(fname) +counts = dict() +temp = list() +for line in fhand: #read each line + words = line.split() #list of words in line + for word in words: + counts[word] = counts.get(word,0) + 1 +bigword = None +bigcount = 0 +for k,v in counts.items(): + if v > bigcount: + bigcount = v + bigword = k +print(bigword, bigcount)