Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pyton count senteses in a text file

fname = "gettysburg.txt"

num_lines = 0
num_words = 0
num_chars = 0

with open(fname, 'r') as f:
    for line in f:
        words = line.split()

        num_lines += line.count(".")
        num_words += len(words)
        num_chars += len(line.replace(' ', ''))
Comment

PREVIOUS NEXT
Code Example
Python :: df max count syntax 
Python :: input check in pygame 
Python :: convert plt.show to image to show opencv 
Python :: pandas drop 1970 
Python :: filtering certain rows in python that contains a part of string 
Python :: pydub audiosegment to numpy array 
Python :: python how to add a new key to a dictionary 
Python :: reverse list in python 
Python :: flask stream with data/context 
Python :: get Fiscal year 
Python :: python open file check error 
Python :: threading in python 
Python :: pytest for loop 
Python :: us states and capitals dictionary 
Python :: how to make a static variable in python 
Python :: np evenly spaced array 
Python :: histogram python 
Python :: pass integer by reference in Python 
Python :: python ip camera 
Python :: How to remove case sensitive django filter 
Python :: get_or_create in django 
Python :: first step creating python project 
Python :: how to parse http request in python 
Python :: how to average only positive number in array numpy 
Python :: DecisionTreeClassifier 
Python :: python string replace 
Python :: iloc pandas 
Python :: circle python programe 
Python :: how to make a python file delete itself 
Python :: defining function in python 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =