Question
use python
019/Lab3.pdf python Exercise 2 Find out most common words in the book omma lane Cluaten The most common words are: to 5242 th
0 0
Add a comment Improve this question Transcribed image text
Answer #1

filename=one.txt 1 s = open(filename). read(). split() 7 for word in s if word in f: f[word] +=1 else: 10 f[word] = 1 12 13

filename = "one.txt"

s = open(filename).read().split()

f = {}

for word in s:

if word in f:

f[word] +=1

else:

f[word] = 1

s = [(one, f[one]) for one in sorted(f, key = f.get, reverse = True)]

for i in range(10):

print(s[i][0],":", s[i][1])

''' OUTPUT

King : 3
Once : 1
there : 1
lived : 1
a : 1
went : 1
for : 1
fishing : 1
and : 1
has : 1

'''

Add a comment
Know the answer?
Add Answer to:
use python 019/Lab3.pdf python Exercise 2 Find out most common words in the book omma lane...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT