To write a python program for getting the word count from the contents of a file using command line arguments.
PC Anaconda - Python 3.7
First import sys.
Keep the variable count as empty.
Open the file and access the file in reading mode.
Iterate the loop using for loop in line.split().
Using if condition increment the value.
Print the variable count and close the file
import sys
count = {}
with open (doc2, 'r') as f:
for line in f:
for word in line.split():
if word not in count:
count [word] = 1
else:
count [word]+=1
print (count)
f.close()
Thus the program is written to find the word count from the contents of a file using command line arguments.