没有什么用的word-counter

没有什么技术含量,但是算留作纪念吧。

程序功能:实现一篇英语文章的所有句子按照句子里面的单词个数,由多至少排序。

完成用时:约2小时

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

你可能感兴趣的:(没有什么用的word-counter)