Given a text file (FILE1) with lots of words (ex, an ebook),
and another file (FILE2) with a list of blacklist words
(slangs, porn, etc.), write a program to find the top 100
words(most frequent 100 words) from FILE1 which are not
present in FILE2.

Answer Posted / siva kumar reddy dandu

Steps to solve this.
1. open FILE1 in read mode
2. read content by using read()
3 split content by using
so that you can get lines
4 split lines by split(' ') so that you can get words
5 repeat above 4 lines with file FILE2
6 iterate words list and create dictionary word and frequency as key values.
skip the value if it is found in file2 key words.
7 sort dict by using x= list(sorted(wordsarr.items(),wordsarr.get, reverse=true)
so that we can get sorted dict in desc order.
8 return top 100 words by using print(x[:101])

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the different file-processing modes with python?

478


How do I exit python?

441


What are built in types in python?

480


How can you generate random numbers in python?

424


Is python interpreted language?

425






Boolean have 2 possible values. Are there types in python that have 3 possible values?

487


What does all do in python?

433


What is the purpose of a // operator?

468


What is the purpose of the pythonstartup environment variable?

475


What is super () in python?

443


Is anaconda the same as python?

427


How do you alphabetize a list in python?

446


Is python interpreter or compiler?

446


You are having multiple memcache servers running python, in which one of the memcacher server fails, and it has your data, will it ever try to get key data from that one failed server?

451


How do you add elements to a list in python?

412