当前第2页 返回上一页
同时删除多种不同字符:translate() py3中为str.maketrans()做映射
1 2 3 4 5 6 7 |
s = 'abc123xyz'
print ( str .maketrans( 'abcxyz' , 'xyzabc' ))
print (s.translate( str .maketrans( 'abcxyz' , 'xyzabc' )))
|
去掉unicode字符中音调
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import sys
import unicodedata
s = "Zhào Qián Sūn Lǐ Zhōu Wú Zhèng Wáng"
remap = {
ord ( '\t' ): '',
ord ( '\f' ): '',
ord ( '\r' ): None
}
a = s.translate(remap)
cmb_chrs = dict .fromkeys(c for c in range (sys.maxunicode) if unicodedata.combining( chr (c)))
b = unicodedata.normalize( 'NFD' , a)
print (b.translate(cmb_chrs))
|
相关推荐:
python 按照固定长度分割字符串的方法
以上就是python如何去除字符串中不想要的字符的详细内容,更多文章请关注木庄网络博客!!
返回前面的内容
相关阅读 >>
Python中class是什么意思
Python中变量和数据类型介绍
Python操作mongodb的9个步骤
Python根据年份月份输出天数
Python的int是什么
Python 是什么?
Python中typing模块的介绍(代码实例)
Python将多个映射合并为单个映射的方法与分析(代码实例)
Python中关于上下文管理器的详解
Python中的mkdir方法怎么用
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python如何去除字符串中不想要的字符