Table of Contents
show
Word count
import sys
file=open(sys.argv[1],"r+")
wordcount={}
for word in file.read().split():
if word not in wordcount:
wordcount[word] = 1
else:
wordcount[word] += 1
file.close()
print ('Words in the File' , 'Count')
for key in wordcount.keys():
print (key , wordcount[key])
Output


Copy file
sf = open("ipfile.txt","r")
df = open("opfile.txt","w")
while(True):
nl = sf.readline()
if nl == "":
break
df.write(nl)
print("File Copied")
sf.close()
df.close()
Output



Views: 0