gpt4 book ai didi

Python - 如何改变像é这样的字母

转载 作者:太空宇宙 更新时间:2023-11-04 08:42:02 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com