Forked from boniattirodrigo/removerAcentosECaracteresEspeciais.py
Created
May 25, 2020 05:28
-
-
Save wdownload/e7c8df616f8fe20cd98a3430e13d9ce0 to your computer and use it in GitHub Desktop.
Remover acentos e caracteres especiais em Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unicodedata | |
import re | |
""" | |
A remoção de acentos foi baseada em uma resposta no Stack Overflow. | |
http://stackoverflow.com/a/517974/3464573 | |
""" | |
def removerAcentosECaracteresEspeciais(palavra): | |
# Unicode normalize transforma um caracter em seu equivalente em latin. | |
nfkd = unicodedata.normalize('NFKD', palavra) | |
palavraSemAcento = u"".join([c for c in nfkd if not unicodedata.combining(c)]) | |
# Usa expressão regular para retornar a palavra apenas com números, letras e espaço | |
return re.sub('[^a-zA-Z0-9 \\\]', '', palavraSemAcento) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment