count words in a string python code example
Example: count words in string python
import string
# sentence = ""
sentence = str(input("Enter here: "))
# Remove all punctuations
sentence = sentence.translate(str.maketrans('', '', string.punctuation))
# Remove all numbers"
sentence = ''.join([Word for Word in sentence if not Word.isdigit()])
count = 0;
for index in range(len(sentence)-1) :
if sentence[index+1].isspace() and not sentence[index].isspace():
count += 1
print(count)