沒有什么技術(shù)含量,但是算留作紀(jì)念吧腿准。
程序功能:實(shí)現(xiàn)一篇英語文章的所有句子按照句子里面的單詞個(gè)數(shù)游沿,由多至少排序。
完成用時(shí):約2小時(shí)
#word counting program
#Designed By Xc Li
#Oct. 2015
#coding:utf-8
importos
print'Instructions:\n1.Only support txt files\n2.Name filename in English\n3.Put the file to be analysed and this program in the same folder\nHave Fun:)'
file_name=raw_input("File name:")
try:
fh=open(file_name)
except:
print"Error"
sentence=list()
forlineinfh:
#print line ok
line=line.strip()
line=line.replace('!','.')
se=line.split('.')
sentence.append(se)
# print sentence
count=1
s_list=list()
forsinsentence:
fors_1ins:
words=s_1.split()
s_1=str(len(words))+' '+s_1
# print s
iflen(words)>0:
s_list.append(s_1)
# print s_list
s_list.sort()
forsins_list:
prints
print'Done!'
os.system("pause")