ayush singhal ayush singhal - 4 months ago 11
Python Question

count word occurances in a string

I have the following situation:

str='this is the string that Luci want to parse for a dataset uci at web'
word='uci'

str.count(word)=?


I want to count only 'uci' which appear independently (not inside any word)
so the output should be 1 and not 2!

Python script required.

Answer
>>> s = 'this is the string that Luci want to parse for a dataset uci at web'
>>> s.split(' ').count('uci')
1