In this we are going to see how to print a Python Program to Count the Number of Words in a String, using Generators in Python Programming Language.
def count_words(test_string, word):
for i in test_string:
if i == word:
yield i
test_string = "The big brown bear, was big enough to hide the big hut behind it"
word = "big"
count = 0
for j in count_words(test_string.split(), word):
count = count + 1
print("The count is ", count)
# Coded By Dhiraj Shelke
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP