Skip to content

Instantly share code, notes, and snippets.

@russelnickson
Created January 14, 2010 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save russelnickson/277055 to your computer and use it in GitHub Desktop.
Save russelnickson/277055 to your computer and use it in GitHub Desktop.
Find the Longest Sentence
import sys
from string import split
f=open(sys.argv[1])
content=f.read()
#print content
sentence=split(content,'.')
largest=smallest=len(sentence[0])
total=0
print sentence
large=small=len(sentence[1])
tot=0
count=0
for a in sentence:
if len(a)>0:
count+=1
if len(a)>large:
large=len(a)
if len(a)<small:
small=len(a)
tot+=len(a)
print 'the lenght of sentence '+str(count)+' is = '+str(len(a))
print 'the longest sentence is = '+str(large)
print 'the smallest sentence is = '+str(small)
print 'the avg. sentence length is = '+str(tot/(len(sentence)-1))
#'-1' is because afte last fullstop an empty element is also taken
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment