当前第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多线程的优点是什么?六大优点助你了解多线程
Python里lambda是什么
Python怎么赋值
Python中什么是语句块?
Python怎么调试?
Python 中类的静态变量怎么理解
Python工作岗位有哪些
字典的什么方法返回字典的键列表
Python中实现将多个print输出合成一个数组
Python使用pandas处理excel的方法
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python如何去除字符串中不想要的字符