【发布时间】:2012-01-31 11:06:04
【问题描述】:
可能重复:
What is the best way to remove accents in a python unicode string?
Python and character normalization
我想删除重音符号,将所有字符转为小写,并删除所有数字和特殊字符。
例子:
Frédér8ic@ --> 弗雷德里克
建议:
def remove_accents(data):
return ''.join(x for x in unicodedata.normalize('NFKD', data) if \
unicodedata.category(x)[0] == 'L').lower()
有没有更好的方法来做到这一点?
【问题讨论】:
-
您能否编辑您的答案以包含一些所需输入和输出的示例?
-
@Christian Jonassen Frédér8ic@ --> frederic @@àbcd --> abcd %*tréçd --> trecd
-
考虑到 OP 想要的不仅仅是 unicode 规范化,这可能不是重复的。
-
@Abhijit +1。我搜索的效率比我的代码高
标签: python diacritics