Forked from boniattirodrigo/removerAcentosECaracteresEspeciais.py
Created
October 25, 2019 11:42
-
-
Save alsgil13/22bb4d20c20fca7624f599b91e4b92fa 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