-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmost_often_word.py
More file actions
35 lines (34 loc) · 999 Bytes
/
most_often_word.py
File metadata and controls
35 lines (34 loc) · 999 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
array_str = list()
with open("file.txt", "r") as inf:
for line in inf:
lines = line.lower()
string = str()
i = 0
while i < len(lines):
j = i
while not lines[j].isspace():
string = string + lines[j]
j = j + 1
i = j
if j == len(lines):
break
i = i + 1
array_str.append(string)
string = str()
most_often_word = str()
how_often = 0
temp_often = 0
for i in range(len(array_str)):
j = i
while j < len(array_str):
if array_str[j] == array_str[i]:
temp_often = temp_often + 1
j = j + 1
if temp_often > how_often:
most_often_word = array_str[i]
how_often = temp_often
elif temp_often == how_often and array_str[i] < most_often_word:
most_often_word = array_str[i]
how_often = temp_often
temp_often = 0
print(most_often_word + " " + str(how_often))