Question

PYTHON language

Write a program that finds the most used word in scarlet3.txt. Run Original - 1 of 1 Show CodeLens 1 2 f open(scarlet3.txt,

0 0
Add a comment Improve this question Transcribed image text
Answer #1

f=open('scarlet3.txt','r')#opening file in read mode
file=f.readlines()#reading file contents line by line
words={}#dictionary to hold the words in file and their corresponding count
file2=[]#auxilary list for processing
for i in file:#traversing through the file to split the words
file2.append(i.split())
file=[]
file=[j for i in file2 for j in i]#list comparahanson to convert list of lists to a single list of all words in the list
for i in file:#traversing through the words in the file to prepare the dictionary
words[i]=file.count(i)
print(max(words,key=words.get))#getting the word that is used maximum number of times in the file

maxCountinFile.py - C:/Users/sai kumar/AppData/Local/Programs/Python/Python37/m File Edit Format Run Options Window Help f=op

scarlet3.txt

ONE DOLLAR AND EIGHTY-SEVEN CENTS. That was all. And sixty
cents of it was in pennies. Pennies saved one and two at a time by
bulldozing the grocer and the vegetable man and the butcher
until one's cheek burned with the silent imputation of parsimony
that such close dealing implied. Three times Della counted it.
One dollar and eighty-seven cents. And the next day would be
Christmas.
There was clearly nothing left to do but flop down on the
shabby little couch and howl. So Della did it. Which instigates the
moral reflection that life is made up of sobs, sniffles, and smiles,
with sniffles predominating.
While the mistress of the home is gradually subsiding from the
first stage to the second, take a look at the home. A furnished flat
at $8 per week. It did not exactly beggar description, but it certainly had that word on the look-out for the mendicancy squad.
In the vestibule below was a letter-box into which no letter
would go, and an electric button from which no mortal finger
could coax a ring. Also appertaining thereunto was a card bearing
the name 'Mr. James Dillingham Young.'
The 'Dillingham' had been flung to the breeze during a former
period of prosperity when its possessor was being paid $30 per
week. Now, when the income was shrunk to $20, the letters of
'Dillingham' looked blurred, as though they were thinking seriously of contracting to a modest and unassuming D. But whenever
Mr. James Dillingham Young came home and reached his flat
above he was called 'Jim' and greatly hugged by Mrs. James
Dillingham Young, already introduced to you as Della. Which is
all very good.
Delia finished her cry and attended to her cheeks with the
powder rag. She stood by the window and looked out dully at a
grey cat walking a grey fence in a grey backyard. To-morrow
would be Christmas Day, and she had only $1.87 with which to
buy Jim a present. She had been saving every penny she could for

output

RESTART: C:/Users/sai kun le.py the >>|

As you can see in the above output 'the' is the most repeated word in the given file which is repeated 21 time.

Feel free to ask me if you need any clarifications.

Give thumbs up if my work is helpful.

Thank you:).

Add a comment
Know the answer?
Add Answer to:
PYTHON language Write a program that finds the most used word in scarlet3.txt. Run Original -...
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
  • Using C, Write a program to alphabetically merge the three word list files (american0.txt, american1.txt, and...

    Using C, Write a program to alphabetically merge the three word list files (american0.txt, american1.txt, and american2.txt). Each file will have words in random order. The output must be a file called words.txt. Note that you cannot cheat by using Linux commands to do this. It must be done entirely in your C code. File format: apple banana pear . . . Hint: Program will need to utilize double pointers. More Hints: 1. Assume no word is bigger that 50...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a function...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a function named capital_letter that accepts a string as an argument and checks if each word in the string begins with a capital letter. If so, the function will return true, otherwise, return false. Please see the outcome below: Outcome number 1: Enter a string: Python Is Really Fun! True Sample run number 2: Enter a string: i Love Python False Note: Try to keep this...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a function named smaller that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all numbers in the list that are smaller than the number n. Write a code that declares and initializes a list of numbers and a variable number and pass them to the function to test it. Please see the outcome below:...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a function named smaller that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all numbers in the list that are smaller than the number n. Write a code that declares and initializes a list of numbers and a variable number and pass them to the function to test it. Please see the outcome below:...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a function named smaller that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all numbers in the list that are smaller than the number n. Write a code that declares and initializes a list of numbers and a variable number and pass them to the function to test it. Please see the outcome below:...

  • Python Assignment Tasks 1. Place the two provided plaintext files (file_1.txt, file_2.txt) on your desktop. 2....

    Python Assignment Tasks 1. Place the two provided plaintext files (file_1.txt, file_2.txt) on your desktop. 2. Write a Python program named fun_with_files.py. Save this file to your desktop as well. 3. Have your program write the Current Working Directory to the screen.   4. Have your program open file_1.txt and file_2.txt, read their contents and write their contents into a third file that you will name final.txt . Note: Ponder the open‐read/write‐close file operation sequence carefully. 5. Ensure your final.txt contains...

  • I need python help .. I need to know if a user were to input 3...

    I need python help .. I need to know if a user were to input 3 commands to a program and run it such as specify: Usage: ./filemaker INPUTCOMMANDFILE OUTPUTFILE RECORDCOUNT (./filemaker is the program)( (INPUTCOOMANDFUILE= a text file that contains key words that need to be searched through then decided what to do ) (RECORDCOUNT= number) Given an input file that contains the following: That specifies the text, then the output, and the number of times to be repeated...

  • Write a program that reads each word from A1.txt and check if it's a palindrome or...

    Write a program that reads each word from A1.txt and check if it's a palindrome or not. Show your output in the file Bl.txt. The total number of words in the file can change. You must use c-string or character arrays. Using String datatype and strrev() function are not allowed in this problem. "A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward." (Wikipedia) Sample Input: series madam Sample Output: yes

  • The goal is to write a program that reads two novels, finds the top-k most common...

    The goal is to write a program that reads two novels, finds the top-k most common words in each, and displays any words that were common in one novel, but not the other. Here is my output for k = 20: $ python solution.py k= 20 Words used more in Pride and Prejudice: she be his for Words used more in Jane Eyre: you my is me This seems to mostly reflect the difference in narration: Pride and Prejudice is...

  • Write a Python program to read lines of text from a file. For each word (i.e,...

    Write a Python program to read lines of text from a file. For each word (i.e, a group of characters separated by one or more whitespace characters), keep track of how many times that word appears in the file. In the end, print out the top twenty counts and the corresponding words for each count. Print each value and the corresponding words, in alphabetical order, on one line. Print this in reverse sorted order by word count. You can assume...

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