Created
December 22, 2015 19:40
-
-
Save sgobin/1f9abd1d4febcf7329de to your computer and use it in GitHub Desktop.
Achar palíndromos em uma lista usando python. Substitua o arquivo em open() com o que você deseja.
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
#Abrir o arquivo | |
f = open('pt-BR-utf8', 'r') | |
#ler uma linha | |
for line in f: | |
palavra = line.replace("\n", "") | |
palavra = palavra.lower() | |
#inverter a palavra | |
palavra_reversa = palavra[::-1] | |
#comparar se igual, printar | |
if len(palavra) == 1: | |
continue | |
elif palavra == palavra_reversa: | |
print(palavra) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Todo's
Notas