Count words in a string in Python

0 votes
I have a python string and I want to find how many times a particular word has been used in that string. How can I do it in Python?
Apr 4 in Python by Raj
9 views

1 answer to this question.

0 votes

You have to use the count method to do this:

statement="how many have I use how many and how"
x=statement.count("how")
print (x)
answered Apr 4 by Shri

Related Questions In Python

+1 vote
4 answers

Count the frequency of an item in a python list

To count the number of appearances: from collections ...READ MORE

answered Oct 18, 2018 in Python by tinitales
149 views
0 votes
1 answer

Looping over a string in python

for c in "string": ...READ MORE

answered May 28, 2018 in Python by Nietzsche's daemon
• 4,260 points
13 views
0 votes
2 answers

Finding the index of a character in python string

You can use word.find('o') as well to ...READ MORE

answered Jun 1, 2018 in Python by george
• 200 points
79 views
0 votes
1 answer

How to print first character of each word in upper case of a string in Python

You can use split() using space as ...READ MORE

answered Jun 1, 2018 in Python by george
• 200 points
1,379 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 127 views
+4 votes
6 answers
0 votes
1 answer

How to change one character in a string in Python?

Python strings are immutable, you change them ...READ MORE

answered Dec 4, 2018 in Python by Nymeria
• 3,500 points
35 views
0 votes
1 answer

How can I get the count of a list in Python?

len() >>> mylist=[] >>> print len(mylist) 0 READ MORE

answered Dec 12, 2018 in Python by charlie_brown
• 7,710 points
56 views