Created
January 14, 2010 10:28
-
-
Save russelnickson/277055 to your computer and use it in GitHub Desktop.
Find the Longest Sentence
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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