1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
fgiga [73]
4 years ago
9

Write a function named wordLineCount with the following input and output: Input: a string parameter, inFile, that is the name of

a file Output: return a dictionary in which each unique word in inFile is a key and the corresponding value is the number of lines on which that word occurs The file inFile contains only lower case letters and white space. For example, if the file ben.txt contains these lines tell me and i forget teach me and i remember involve me and i learn then the following would be correct output:
>>> print(wordLineCount('ben.txt')){'remember': 1, 'and': 3, 'tell': 1, 'me': 3, 'forget': 1, 'learn': 1,'involve': 1, 'i': 3, 'teach': 1}

Computers and Technology
1 answer:
Galina-37 [17]4 years ago
6 0

Answer:

def wordLineCount(file):

   dic = {}

   with open(file,'r') as file:

       

       text = file.read()

       text = text.strip().split()

       for word in text:

           if word in dic:

               dic[word] += 1

           else:

               dic[word] = 1

   return dic

print(wordLineCount('ben.txt'))

Explanation:

The programming language used is python.

The program starts by defining the function, an empty dictionary is created to hold the words and the number of times that they occur. the with key word is used to open the file, this allows the file to close automatically as soon as the operation on it is finished.

The data in the file is read to a variable text, it is striped from all punctuation and converted to a list of words.

A FOR loop and an if statement is used to iterate through every word in the list and checking if they are already in the dictionary. if the word is already contained in the dictionary, the number of occurrences increases by one. otherwise, it is added to the dictionary.

check the attachment to see code in action.

You might be interested in
Each frame is composed of a number of colors recorded in digital format; we call these pixels. What information does the number
Nookie1986 [14]
I'd say the size of the frame.

The size, quantity and color combination of pixels is measured in terms of display resolution. A resolution, however, is the number of pixels in an image and is identified by the width and the height. How you’ve set the resolution for the display screen will determine the specific size of the pixels.






7 0
4 years ago
Which of the following activities do not involve Information technology​
m_a_m_a [10]

Answer:

You didn't add any information technology sentence below

: / Have a great day

8 0
3 years ago
The type of human hair wig that is the most costly is:
RSB [31]

Answer: india

Explanation:

5 0
3 years ago
A _____ provides a file-system interface which allows clients to create and modify files.
stiv31 [10]
The correct answer is a file-server system. Hope this helps!
3 0
4 years ago
sales reps at universal containers use salesforce on their mobile devices. They want a way to add new contacts quickly and then
Mamont248 [21]

Answer:

Build a global action to create Contacts

Explanation:

Based on the information given the mobile solution that an app builder should recommend should be GLOBAL ACTION because global action enables new contact to be created quickly ,Global actions also enables the creation or update of records as well sending email, all without leaving the page the person is working on which is why GLOBAL ACTION is often recommended because it saves time.

6 0
4 years ago
Other questions:
  • Are sql injections legal?
    15·1 answer
  • Sera ético cargar a la www un vídeo que no es de su propiedad
    15·1 answer
  • Which of the following are true about the PUSH instruction?
    9·1 answer
  • Where can you go in QuickBooks Online to import a list of products and services? Select the Quick Create icon and under the Tool
    12·1 answer
  • What are the long-term consequences for John’s health and wellness if he continues to use this technique
    15·1 answer
  • List the instructions of how you would make a PBJ sandwich as a series of five (5) steps (tasks) in the first column Complete th
    14·1 answer
  • Francis has created a new program. However, Francis used some objects from another program to run methods in the current program
    14·2 answers
  • Identify methods to improve programming skills.
    15·1 answer
  • a network administrator for a large oil company has discovered that a host on the company network has been compromised by an att
    15·1 answer
  • The first time that a particular visitor loads a web site page is called a(n) _____.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!