手机
当前位置:查字典教程网 >脚本专栏 >python >Python实现统计英文单词个数及字符串分割代码
Python实现统计英文单词个数及字符串分割代码
摘要:字符串分割复制代码代码如下:str="a|and|hello|||ab"alist=str.split('|')printalist结果复制...

字符串分割

复制代码 代码如下:

str="a|and|hello|||ab"

alist = str.split('|')

print alist

结果

Python实现统计英文单词个数及字符串分割代码1

复制代码 代码如下:

str="a hello{这里换成5个空格}world{这里换成3个空格}"

alist=str.split(' ')

print alist

Python实现统计英文单词个数及字符串分割代码2

统计英文单词的个数的python代码

复制代码 代码如下:

# -*- coding: utf-8 -*-

import os,sys

info = os.getcwd() #获取当前文件名称

fin = open(u'c:/a.txt')

info = fin.read()

alist = info.split(' ') # 将文章按照空格划分开

fout = open(u'c:/count.txt', 'w')

fout.write('n'.join(alist)) # 可以通过文本文件的行号同样看到效果

##fout.write('%s' % alist)

fout.close()

allen = len(alist) # 总的单词数

nulen = alist.count('') # 空格的数量

print "words' number is",allen

print "null number is",nulen

print "poor words number is", allen-nulen # 实际的单词数目

fin.close()

【Python实现统计英文单词个数及字符串分割代码】相关文章:

python脚本实现统计日志文件中的ip访问次数代码分享

python 字符串格式化代码

python求斐波那契数列示例分享

python用字典统计单词或汉字词个数示例

Python 文件重命名工具代码

基于Python实现的扫雷游戏实例代码

布同 统计英文单词的个数的python代码

python 实现堆排序算法代码

python实现的登陆Discuz!论坛通用代码分享

Python版的文曲星猜数字游戏代码

精品推荐
分类导航