Write a program to count the no. of occurrence of word in
given string
Ex- Ram is good boy. Ram is doing good job.
Ram – 2
is – 2
good – 2
boy – 1
doing –1
job – 1



Write a program to count the no. of occurrence of word in given string Ex- Ram is good boy. Ram i..

Answer / Ashish Maurya

Here is a simple Python solution:nn```ndef count_words(string):n words = string.split()n counts = {} n for word in words:n if word in counts:n counts[word] += 1n else:n counts[word] = 1n return countsn```nFor your example, the function would output: {"Ram":2,"is":2,"good":2,"boy":1,"doing":1,"job":1}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Engineering AllOther Interview Questions

why do you want to join tcs

1 Answers   TCS,


what is recursion in c language?

1 Answers  


if a customer's blackberry stopped syncing their calendar wirelessly what would you do?if a customber deleted mail from his blackberry but it did delete from his mailbox how would ypu resolve this

1 Answers  


find the next number:60 24 7 4

1 Answers  


If navara d40 injektor damage.what is the problem when we drive??

1 Answers  


i want to do oracle certification..could any one pleas tell me what is the level 1 certification exam in oracle? how do we get dumps?

1 Answers   TCS,


What experience do you have in RMA?s (returned material authorizations?)

0 Answers  


Why the secondary ip address of interface is not advertising in IGP cloud?

2 Answers   HCL,


2. A product selected for testing is equally likely to have been produced by one the 6 machines/processes. (i) Determine sample space ‘S’ (ii) What is the probability that the product is from machine 1? (iii) What is the probability that the product is from machine 2 or machine 4? (iv) What is the probability that the product is from both machine 5 and machine 3? (v) What is the probability that the product is not from machine 6? (vi) What is the probability that the product is not from either machine 6 or machine 1?

1 Answers  


URGENT.. I want to make a really good project using ADVANCE JAVA Can anyone suggest any great n innovative ideas I have nearly 4 months to make it so it can be big n time consuming... It should be Web Based also... It can use more than one Java Technologies.. Please suggest me something innovative n great.. thanks:

1 Answers  


i am diploma 3rd year student tell me sbout mpsc exam or any other

1 Answers  


How Good is tata nano?

0 Answers   TATA,


Categories
  • Civil Engineering Interview Questions Civil Engineering (5086)
  • Mechanical Engineering Interview Questions Mechanical Engineering (4453)
  • Electrical Engineering Interview Questions Electrical Engineering (16638)
  • Electronics Communications Interview Questions Electronics Communications (3918)
  • Chemical Engineering Interview Questions Chemical Engineering (1095)
  • Aeronautical Engineering Interview Questions Aeronautical Engineering (239)
  • Bio Engineering Interview Questions Bio Engineering (96)
  • Metallurgy Interview Questions Metallurgy (361)
  • Industrial Engineering Interview Questions Industrial Engineering (259)
  • Instrumentation Interview Questions Instrumentation (3014)
  • Automobile Engineering Interview Questions Automobile Engineering (332)
  • Mechatronics Engineering Interview Questions Mechatronics Engineering (97)
  • Marine Engineering Interview Questions Marine Engineering (124)
  • Power Plant Engineering Interview Questions Power Plant Engineering (172)
  • Textile Engineering Interview Questions Textile Engineering (575)
  • Production Engineering Interview Questions Production Engineering (25)
  • Satellite Systems Engineering Interview Questions Satellite Systems Engineering (106)
  • Engineering AllOther Interview Questions Engineering AllOther (1379)