Python 中是否有一个函数可以将 é 转换为 e,或 í 转换为 i?
最佳答案
是的,您可以通过以下过程过滤和映射字符串的字符:
from unicodedata import normalize, category
''.join([c for c in normalize('NFD',original) if category(c) != 'Mn'])
在这里,我从您的问题中过滤掉了这些口音:
>>> original = 'Is there a function in python which converts letters like é to e, or í to i?'
>>> from unicodedata import normalize, category
>>> ''.join([c for c in normalize('NFD',original) if category(c) != 'Mn'])
'Is there a function in python which converts letters like e to e, or i to i?'
关于Python - 如何改变像é这样的字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44101696/