Word in Text
How can I best find out how many times a word appears in a text?
sneekula
Nearly a Posting Maven
2,427 posts since Oct 2006
Reputation Points: 961
Solved Threads: 212
Searching our own Python snippet section there are several hits under 'wordcount' and word frequency. These snippets are probably more complex than what you need, so here is a very simple way to do it ...
# Chinese wisdom ...
str1 = """Man who run in front of car, get tired.
Man who run behind car, get exhausted."""
print str1.count('Man') # 2
BTW, Google result --> about1,110,000 for python word count . That should keep you busy for the next ten years.
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417