Forked from boniattirodrigo/removerAcentosECaracteresEspeciais.py
Created
August 11, 2017 17:22
-
-
Save djwesleyborges/55ee6463417ad92ea0eff389aa9a109e 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