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 test mode.
Read the text using read() function.
Split the text using space separator.We assume that words in a sentance are separted by a space character.
The length of the split list should equal the numbers of words in the test file.
You can refine the count by cleaning the string prior to splitting or validating the words after splitting.
End the program.
with open("file1.txt","r") as fp:
data = fp.read()
x = data.split()
print("number of words:",len(x))
Thus the program is written to find the word count from a text.