温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

使用Python怎么将文本中的中英文进行分离

发布时间:2021-03-02 15:35:30 来源:亿速云 阅读:646 作者:戴恩恩 栏目:开发技术

本文章向大家介绍使用Python怎么将文本中的中英文进行分离,主要包括使用Python怎么将文本中的中英文进行分离的使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

python可以做什么

Python是一种编程语言,内置了许多有效的工具,Python几乎无所不能,该语言通俗易懂、容易入门、功能强大,在许多领域中都有广泛的应用,例如最热门的大数据分析,人工智能,Web开发等。

1、超短文本,ASCII识别。

s = "China's Legend Holdings will split its several business arms to go public on stock markets, the group's president Zhu Linan said on Tuesday.该集团总裁朱利安周二表示,中国联想控股将分拆其多个业务部门在股市上市。"
result = "".join(i for i in s if ord(i) < 256)
print(result)
out:
China's Legend Holdings will split its several business arms to go public on stock markets, the group's president Zhu Linan said on Tuesday.

2、unicode编码识别

import re
s = "China's Legend Holdings will split its several business arms to go public on stock markets, the group's president Zhu Linan said on Tuesday.该集团总裁朱利安周二表示,中国联想控股将分拆其多个业务部门在股市上市。"
uncn = re.compile(r'[\u0061-\u007a,\u0020]')
en = "".join(uncn.findall(s.lower()))
print(en)
out:
chinas legend holdings will split its several business arms to go public on stock markets, the groups president zhu linan said on tuesday

中文的编码范围是:\u4e00-\u9fa5,相应的[^\u4e00-\u9fa5]可匹配非中文。

匹配英文时,需要将空格[\u0020]加入,不然单词之间没空格了。

到此这篇关于使用Python怎么将文本中的中英文进行分离的文章就介绍到这了,更多相关的内容请搜索亿速云以前的文章或继续浏览下面的相关文章希望大家以后多多支持亿速云!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI