To write a python program for getting the word count from a text.
PC Anaconda - Python 3.7
Open the in read mode and handle it in text mode.
Read the text using the read() function.
Split the text using space seperator. We assume that words in a sentence are seperated by a space character.
The length of the split list should equal the number of words in the text file.
You can refine the count by cleaning the string prior to splitting or validating the words after splitting.
End the program.
#Developed by: S.Mohan raj
#Reference number:212221230065
num_words =0
with open('text1.txt','r') as file1:
for i in file1:
word =i.split()
num_words += len(word)
print("Number of words={}".format(num_words))
Thus the program is written to find the word count from a text.