1# define string
2string = "Python is awesome, isn't it?"
3substring = "is"
4
5count = string.count(substring)
6
7# print count
8print("The count is:", count)
1import string
2
3# sentence = ""
4sentence = str(input("Enter here: "))
5
6# Remove all punctuations
7sentence = sentence.translate(str.maketrans('', '', string.punctuation))
8
9# Remove all numbers"
10sentence = ''.join([Word for Word in sentence if not Word.isdigit()])
11
12count = 0;
13
14for index in range(len(sentence)-1) :
15 if sentence[index+1].isspace() and not sentence[index].isspace():
16 count += 1
17
18print(count)
1// Count words (text separated by whitespace) in a piece of text
2use std::collections::HashMap;
3
4fn word_count(text: &str) -> HashMap<&str, i32> {
5 let mut map = HashMap::new();
6 for word in text.split_whitespace() {
7 *map.entry(word).or_insert(0) += 1;
8 }
9 map
10}
11
12fn main() {
13 println!("Count of words = {:?} ",word_count("the quick brown fox jumped over the lazy dog"));
14}