0

(Python) Can anyone help with making the code return the number of times the most common word in a string

Example_list = [ ‘ the ‘ , ‘ cat, ‘ ran ‘ , ‘ across’ , ‘ the ‘ , ‘street’, ‘ to ‘ , ‘catch ‘ , ‘ the ‘ , ‘ mouse’] Def most_common_word(data) Print (‘ most_common_word:’, end= ‘ ‘) Return ( word, count) https://code.sololearn.com/cw72jqgvKzNR/?ref=app

8th May 2022, 4:04 PM
Mingo_24
8 Respuestas
+ 4
👉What have you tried so far? 👉Please tag the relevant programming language. 👉Please put your complete code in a script on sololearn playground: Go to Code section, click+, select the programming language, insert your code and save. Come back to this thread, click +, Insert Code, sort for My Code Bits, select your code. 👉You have joined sololearn only a few minutes ago. Maybe you would like to revise some basics before you do this task: https://www.sololearn.com/Course/JUMP_LINK__&&__Python__&&__JUMP_LINK/?ref=app https://www.sololearn.com/Course/Python-for-Beginners/?ref=app
8th May 2022, 4:10 PM
Lisa
Lisa - avatar
+ 3
Using a for loop sounds good. And I see that you tagged dictionaries. So I would use it.
8th May 2022, 4:20 PM
Denise Roßberg
Denise Roßberg - avatar
+ 3
Indentation is essential in Python. Please check the indentation. On each iteration of the loop, check if the current word is in your dictionary: If not, add the word as key with the value 1 If yes, increase the value in the dictionary by 1
8th May 2022, 4:31 PM
Lisa
Lisa - avatar
+ 2
We need to see what YOU tried, so please link your complete code.
8th May 2022, 4:17 PM
Lisa
Lisa - avatar
+ 2
https://code.sololearn.com/c2ruGAzvnv5D/?ref=app Just save all the words in a list , count the number of time each occurs and print the one with the highest occurance . In python it can be done in just a 2 line program.
10th May 2022, 9:47 AM
Anonymous_User
0
This is for homework but so far ive only tried putting a For loop and what is given above is what my professor initially gave us to start out with so i dont have full code
8th May 2022, 4:13 PM
Mingo_24
0
Ive inserted what i started on so far
8th May 2022, 4:27 PM
Mingo_24
0
This is not working because of improper syntax. The syntax should be like this: def func(): # your code
10th May 2022, 3:36 PM
Tawkir Choudhury
Tawkir Choudhury - avatar