Created
December 26, 2010 02:27
-
-
Save fzmaster/755164 to your computer and use it in GitHub Desktop.
Trocar texto inapropriado por outro adequado
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 unittest | |
import re | |
def slang(texto): | |
""" | |
Autor: fzmaster | |
Site: http://www.fzmaster.info | |
Data: 26/12/2010 | |
Problema: Teleprompter | |
http://codingkata.org/katas/unit/teleprompter | |
Substituir trecho da string por texto adequado | |
""" | |
dict = {'babaca':'bacana', 'tosko':'feio', 'bosta':'beleza'} | |
palavra = re.findall(r"\$.+\$", texto) | |
try: | |
dict.has_key(palavra[0][1:-1]) | |
reg = re.sub(r"\$.+\$",dict.get(palavra[0][1:-1]), texto, 1) | |
return reg | |
except : | |
return 'Traducao nao encontrada' | |
class SlangTestCase(unittest.TestCase): | |
def test_slang1(self): | |
assert slang('Ele eh $babaca$') == 'Ele eh bacana' | |
def test_slang2(self): | |
assert slang('Esse codigo ficou $tosko$') == 'Esse codigo ficou feio' | |
def test_slang3(self): | |
assert slang('Este blog eh uma $bosta$') == 'Este blog eh uma beleza' | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment