Created
March 10, 2014 18:50
-
-
Save fmobus/9471650 to your computer and use it in GitHub Desktop.
detectando til em palavras
This file contains 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
# 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