Python Technical Interview Question: 2 -- Word Count program

Опубликовано: 18 Май 2026
на канале: SanjayBedwal
140
6

In this video , we will learn how to create a word count porgram in python

--code
Sample string
in_str = """This is a Sample paragraph . It contains some sample words .
Words are counted in this program .
This program will be in python language
"""

in_str_lower=in_str.lower()
print(in_str_lower)

for word in in_str: print(word + ' iteration')

Convert the paragraph to lowercase and split it into words
words_list = in_str_lower.split()

print(words_list)

Create an empty dictionary to store word counts
word_count_dict = {}

Iterate through the words and update the dictionary
for word in words_list:
if word not in word_count_dict:
word_count_dict[word] = 1
else:
word_count_dict[word] += 1

print(word_count_dict)

Print the word count
for word_key, count_value in word_count_dict.items():
print(f"{word_key}: {count_value}")