python中怎么统计单词并排序
python 中怎么统计单词并排序,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

成都创新互联,是成都地区的互联网解决方案提供商,用心服务为企业提供网站建设、成都app软件开发、微信小程序、系统按需开发网站和微信代运营服务。经过数10年的沉淀与积累,沉淀的是技术和服务,让客户少走弯路,踏实做事,诚实做人,用情服务,致力做一个负责任、受尊敬的企业。对客户负责,就是对自己负责,对企业负责。
lines_count = 0
words_count = 0
chars_count = 0
words_dict = {}
lines_list = []
c1 = ['!', '?', ';', '.', ',']
all_line = ''
import collections
with open('c:\invalid.txt', 'r') as f:
for line in f:
line = line.strip('\n')
lines_count = lines_count + 1
all_line=all_line+line.lower()
# print line
#print all_line
for i in c1:
all_line=all_line.replace(i,' ')
# print all_line
str1=all_line.split(' ')
for i in str1:
if i not in words_dict:
words_dict[i] = 1
else:
words_dict[i] = words_dict[i] + 1
c1=words_dict.items()
c2=[]
for i in c1:
c2.append((i[1],i[0]))
d2={}
d2={}
for i in c2:
d2[i[0]]=i[1]
def mySort(a):
lo = len(a) - 1
i = 0
while i < lo + 1:
j = lo
while j >= i:
if (a[j - 1] > a[j]):
a[j], a[j - 1] = a[j - 1], a[j]
j = j - 1
i = i + 1 if __name__ == '__main__':
for i in sorted(d2.keys()):
print d2[i], ':', i 关于python 中怎么统计单词并排序问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联行业资讯频道了解更多相关知识。
文章名称:python中怎么统计单词并排序
分享网址:http://www.jxjierui.cn/article/pgcjgi.html


咨询
建站咨询
