用 Python 处的相应非重音字母替换重音字母 3
Replace accented letters with the respective non-accented ones at Python 3
我不确定这个流行的 answer 在 Python 3 中是否有效,因为 Python 3 中没有 unicode。
因此,如何在 Python 3 处用相应的非重音字母替换重音字母?
例如,
sentence = 'intérêt'
到
new_sentence = 'interet'
链接的答案引用了第三方模块 unidecode
,而不是 Python 2 的 unicode
类型。
$ python3
Python 3.7.1 (default, Nov 19 2018, 13:04:22)
[Clang 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import unidecode
>>> unidecode.unidecode('intérêt')
'interet'
我不确定这个流行的 answer 在 Python 3 中是否有效,因为 Python 3 中没有 unicode。
因此,如何在 Python 3 处用相应的非重音字母替换重音字母?
例如,
sentence = 'intérêt'
到
new_sentence = 'interet'
链接的答案引用了第三方模块 unidecode
,而不是 Python 2 的 unicode
类型。
$ python3
Python 3.7.1 (default, Nov 19 2018, 13:04:22)
[Clang 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import unidecode
>>> unidecode.unidecode('intérêt')
'interet'