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
A _______ is a group of elements that you want to style in a particular way.
lora16 [44]

a id is a group of elements of that you want to style in a particular way

4 0
3 years ago
Read 2 more answers
What is the term for individual computers and devices that are connected to a network?
nikitadnepr [17]
The correct answer is nodes
7 0
3 years ago
Assume that strikeCounter has already been declared to be a "pointer to int". Assume further that strikeCounter has been initial
Feliz [49]

Answer:

int* strikeCounter ;

int someVal;

scanf("%d", &someVal);

strikeCounter =&someVal;

*strikeCounter =someVal*4;

Explanation:

Here we took one int variable and read that value from user. we assigned that int variable address to pointer variable "strikeCounter " and we are pointing the value of strikecounter as 4 times of that integer variable value

8 0
4 years ago
Computers are not automatic they need human to operate.(true or false)​
Stolb23 [73]

Answer:

true

Explanation: Humans Bring Energy To The world

5 0
2 years ago
Read 2 more answers
Can anybody do Algorithm 2 for me (with Python).<br> Answer = 25 points.
Nostrana [21]

Answer:

age=int(input("Enter age"))

if age>=18:

    print("You are Young")

else

   print("You are child")

Explanation:

if you have any query or any problem kindly ask in comment

5 0
3 years ago
Other questions:
  • Given the following characteristics for a magnetic disk pack with 10 platters yielding 18 recordable surfaces (not using the top
    14·1 answer
  • PLS ANSWER ASAP!
    9·1 answer
  • CHEMISTRY. metal+water》base+...............​
    12·1 answer
  • A college has 2.3 ratio of men to women in its student body you what is the ratio of women to men
    15·1 answer
  • You can divide the code for an application into logical parts by moving some of the code from the main() method to other _______
    8·1 answer
  • While in class you were introduced to the varieties
    7·1 answer
  • ITING THE ANSWER
    9·1 answer
  • Lonnie needs to use a special kind of block in his game that will tell him whether an object has slammed into his car true or no
    13·1 answer
  • What function would you use to calculate the total interest paid for the first year of a mortgage?.
    15·1 answer
  • The project team is creating detailed documents to guide the team. What phase of the project life cycle are they in?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!