Answers for "count how many words in string python"

1

python count how many times a word appears in a string

# credit to Stack Overflow user in source link

sentence.lower().split().count(word)
Posted by: Guest on May-28-2021
0

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)
Posted by: Guest on May-31-2021

Code answers related to "count how many words in string python"

Python Answers by Framework

Browse Popular Code Answers by Language