Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created April 20, 2018 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/c765ea5b36a520eda0dc7078db0799af to your computer and use it in GitHub Desktop.
Save Fhernd/c765ea5b36a520eda0dc7078db0799af to your computer and use it in GitHub Desktop.
Limpiar y asegurar texto. Python.
import unicodedata
import sys
python = 'pýthöñ\fis\tawesome\r\n'
print(python)
mapa_caracteres = {
ord('\t'): ' ',
ord('\f'): ' ',
ord('\r'): None
}
python = python.translate(mapa_caracteres)
print(python)
caracteres_combinados = dict.fromkeys(c for c in range(sys.maxunicode)
if unicodedata.combining(chr(c)))
python = unicodedata.normalize('NFD', python)
print(python)
print(python.translate(caracteres_combinados))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment