Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 334f62a

Browse files
Create Find Highest Occurrences of a Word in a File.py
1 parent 4a418a6 commit 334f62a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name = input("Enter a file: ")
2+
handle = open(name)
3+
4+
counts = dict()
5+
for line in handle:
6+
words = line.split()
7+
for word in words:
8+
counts[word] = counts.get(word, 0) + 1
9+
10+
bigcount = None
11+
bigword = None
12+
for word, count in counts.items():
13+
if bigcount is None or count > bigcount:
14+
bigword = word
15+
bigcount = count
16+
17+
print(bigword, bigcount)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /