当前第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 numpy 点数组去重
Python queue模块
Python编程的一些习惯
Python爬虫能做什么
Python装饰器原理与用法分析
Python之正则表达式中的贪心模式和非贪心模式的用法和区别
Python如何利用lxml对xml进行读写操作教程
Python是什么意思
Python输出语句如何写
Python基础之输入输出和运算符
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python如何去除字符串中不想要的字符