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.
Read the text using read() function.
Read the text using read() function.
You can refine the count by clearing the string prior t splitting or validatting the words after splitting
import sys
count= 0
with open(sys.argv[1],'r') as f1:
for line in f1:
word= line.split()
count += len(word)
print("word count in file = ",count)
Thus the program is written to find the word count from a text.