Skip to content

Instantly share code, notes, and snippets.

@fmobus
Created March 10, 2014 18:50
Show Gist options
  • Save fmobus/9471650 to your computer and use it in GitHub Desktop.
Save fmobus/9471650 to your computer and use it in GitHub Desktop.
detectando til em palavras
# encoding: utf-8
import unicodedata
import sys
from codecs import open
sys.stdout = open("/dev/stdout","w","utf-8");
TIL = unicodedata.lookup('COMBINING TILDE')
def tem_til(v):
for c in unicodedata.normalize('NFKD', v):
if c == TIL:
return True
return False
palavras = [
[ u"pão", True ],
[ u"paco", False ],
[ u"pé", False ],
[ u"putz", False ]
]
for palavra, deveria_ter in palavras:
tem_de_fato = tem_til(palavra)
correto = tem_de_fato == deveria_ter
if correto:
print " ", palavra, deveria_ter, tem_de_fato, correto
else:
print "***", palavra, deveria_ter, tem_de_fato, correto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment