Latin to English alphabet hashing

。_饼干妹妹 提交于 2020-03-03 05:00:04

问题


I have to convert all the latin characters to their corresponding English alphabets. Can I use Python to do it? Or is there a mapping available?

Unicode values to non-unicode characters

Ramírez Sánchez should be converted to Ramirez Sanchez.


回答1:


It looks like what you want is accent removal. You can do this with:

def strip_accents(text):
    return ''.join(char for char in
                   unicodedata.normalize('NFKD', text)
                   if unicodedata.category(char) != 'Mn')

>>> strip_accents('áéíñóúü')
'aeinouu'
>>> strip_accents('Ramírez Sánchez')
'Ramirez Sanchez'

This works fine for Spanish, but note that it doesn't always work for other languages.

>>> strip_accents('ø')
'ø'


来源:https://stackoverflow.com/questions/4512590/latin-to-english-alphabet-hashing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!