To write a python program for getting the word count from a text.
PC Anaconda - Python 3.7
Open the file in read mode and handle it in text mode
Read the text using read() function.
Split the text using space separator .we assume that words in a sentence are separated by a space character.
The length of the split list should equal the numbe of words in the text file.
You can refine the count by clearing the string prior t splitting or validatting the words after splitting
End the program
num_words =0
with open('text.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.