python中是否有一个函数将é转换为e或í转换为i?
答案 0 :(得分:5)
是的,您可以通过以下过程过滤和映射字符串的字符:
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?'