python判断英文
来源:互联网 发布:淘宝下架的宝贝在哪里找 编辑:程序博客网 时间:2024/06/14 06:35
#!/usr/bin/python#-*-coding:utf-8-*-__author__ = 'lxw'#dictionary.txt的下载地址为:http://pan.baidu.com/s/1i4JL4RNimport stringdef loadEnglish():#这个函数加载字典文件 dicFile = open('dictionary.txt') english_word= {} for word in dicFile.read().split('\n'): english_word[word]=None return english_wordENGLISH_WORDS = loadEnglish()def removenonLetters(message):#移除非字母字符,包括标点符号和数字 letterOnly = [] allLetter = string.uppercase+string.lowercase+' \n\t' for i in message: if i in allLetter: letterOnly.append(i) return "".join(letterOnly)def getEnglishCount(message):#得到一段字符串中单词的个数 message = message.upper() message = removenonLetters(message) match = 0 words = message.split() if len(words)==0: return 0.0 for word in words: if word in ENGLISH_WORDS.keys(): match+=1 return float(match)/len(words)def isEnglish(message,wordPercentage=20,letterPercentage=85):#调用这个函数判断一段字符串是否问一段英文.如果是则返回True wordMatch = getEnglishCount(message)*100 >= wordPercentage removedMsg = removenonLetters(message) letterMatch = (len(removedMsg)/float(len(message)))*100>=letterPercentage return wordMatch and letterMatch
阅读全文
0 0
- python判断英文
- python利用utf-8编码判断中文英文字符(转)
- python利用utf-8编码判断中文英文字符
- python利用utf-8编码判断中文英文字符
- python 利用utf-8编码判断中文英文字符
- 判断是否有英文
- 判断中文、英文、数字
- iOS 英文判断
- python判断unicode是否是汉字,数字,英文,或者其他字符
- python判断unicode是否是汉字,数字,英文,或者其他字符
- python判断unicode是否是汉字,数字,英文,或者其他字符
- python判断unicode是否是汉字,数字,英文,或者其他字符
- python 统计 英文 单词
- Python 去英文标点
- python 处理英文步骤
- Python 英文分词
- Python 英文分词
- [python]反转英文句子
- Android的第一次课_上课代码_上课实例_TextView控件_LinearLayout_gravity属性
- 解决jquery选择器id中带点的获取不到
- 设计模式—责任链模式(二十)
- 前端网站资源精编!!
- JAVA 封装的定义
- python判断英文
- memcached安装
- 数据结构——00基本概念
- Android 开发者的 RxJava 详解
- C语言经典面试题(基础题)
- Oracle Commit
- Python Pip安装时出现UnicodeEncodeError: ‘ascii’ codec can’t encode characters……
- 学习淘淘商城第九十九课(展示购物车列表)
- 一个不爱看书的人记录一下思念看的书