Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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"))
Comment

PREVIOUS NEXT
Code Example
Python :: twilio python 
Python :: flask run on ip and port 
Python :: list of files in python 
Python :: cv2.adaptiveThreshold() 
Python :: standardscaler in machine learning 
Python :: django read mesage 
Python :: standard module 
Python :: list of characters python 
Python :: python live server 
Python :: wait() in python tkinter 
Python :: sns time series plot 
Python :: python rock paper scissor 
Python :: fetch python 
Python :: how to average in python with loop 
Python :: vsc python close all functions 
Python :: sort json python 
Python :: coronavirus program in python 
Python :: neural network import 
Python :: avatar discord.py 
Python :: save pandas into csv 
Python :: python os exists 
Python :: python create random matrix 
Python :: python little endian to big endian 
Python :: show aruco marker axis opencv python 
Python :: python datetime time in seconds 
Python :: python wait until 
Python :: remove whitespace in keys from dictionary 
Python :: flask post vs get 
Python :: Resource punkt not found. Please use the NLTK Downloader to obtain the resource: 
Python :: install python setuptools ubuntu 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =