Program to find most used word in text file using Python
count =
0
;
word = "";
maxCount =
0
;
words = [];
file = open(
"data.txt"
,
"r"
)
for
line
in
file:
string = line.lower().replace(
','
,
''
).replace(
'.'
,
''
).split(
" "
)
for
s
in
string:
words.append(s)
for
i
in
range(
0
, len(words)):
count =
1
for
j
in
range(i+
1
, len(words)):
if
(words[i] == words[j]):
count = count +
1
if
(count > maxCount):
maxCount = count
word = words[i]
print
(
"Most repeated word: "
+ word)
file.close()
Run Program
write some text here
Computer once meant a person who did computations, but now the term almost universally refers to automated electronic machinery. The first section of this article focuses on modern digital electronic computers and their design, constituent parts, and applications. The second section covers the history of computing. For details on computer architecture, software, and theory, see computer science.
Clear
<<
>>
Explanation of program here>>>