当前第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初学者 anaconda入门使用指南完整版_Python
Python变量赋值的步奏详解
Python生成任意范围任意精度的随机数的方法
Python print用法详解
Python Pythonpath是什么意思?
Python轻松实现图片旋转
Python中import有什么用法
Python中列表怎么排序
Python如何绘制心形
Python如何判断是否为浮点数
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python如何去除字符串中不想要的字符