count the frequency of words in a file
from collections import Counter
def word_count(fname):
with open(fname) as f:
return Counter(f.read().split())
print("Number of words in the file :",word_count("test.txt"))
count the frequency of words in a file
from collections import Counter
def word_count(fname):
with open(fname) as f:
return Counter(f.read().split())
print("Number of words in the file :",word_count("test.txt"))
Python program that takes a text file as input and returns the number of words of a given text file
with open('file1.txt','r+') as f:
numw=0
for line in f:
words= line.split()
print(words)
numw += len(words)
print(numw)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us