+ 1

Word equation!

Hello everyone! I am trying to make a code that can figure out how many times a user input word is written in a unser input text. What is the easiest way to do this? I am trying to learn python and have found a way it might work. If you have some websites or anything that might help please like them :)

6th Apr 2018, 6:15 AM
Rasmus Birk Knudsen
Rasmus Birk Knudsen - avatar
7 odpowiedzi
+ 2
Try this. Its just a prototype. Ask questions if unsure. https://code.sololearn.com/c6FsGQPvqy4l/?ref=app
6th Apr 2018, 9:50 AM
Louis
Louis - avatar
+ 7
You might want to start from here: https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2475/?ref=app Regular expressions are most likely the thing you need.
6th Apr 2018, 6:31 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 4
How many times a user input word is written in a [what] ? Could you be a bit more clear, or maybe provide an example?
6th Apr 2018, 6:20 AM
Fox
Fox - avatar
+ 4
The easiest might be to open the file, .read() it, .split() and .strip() it and .count(word) it ;)
6th Apr 2018, 6:37 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
0
Okay i will try to be a bit more clear. If i write a text including 3000 word. Then i want to find out how many time a have written "many" for example. what would be the easiest way to code this?
6th Apr 2018, 6:30 AM
Rasmus Birk Knudsen
Rasmus Birk Knudsen - avatar
0
nice! Thank you 😊
6th Apr 2018, 10:04 AM
Rasmus Birk Knudsen
Rasmus Birk Knudsen - avatar
0
if i were to count the percentage of the words in the text, how do you think this can be made? For example, Quick stand for 4 % of the text and so on :)
6th Apr 2018, 10:08 AM
Rasmus Birk Knudsen
Rasmus Birk Knudsen - avatar