Created
February 9, 2013 00:57
-
-
Save alenbasic/4743285 to your computer and use it in GitHub Desktop.
List of palindromes based on the words file in *nix systems.
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
a = [] | |
b = [] | |
i = 0 | |
z = 0 | |
for line in open('/usr/share/dict/words', 'r').readlines(): | |
while i < len(line)-2: | |
a.append(line[i]) | |
i = i + 1 | |
while i > 0: | |
b.append(line[i]) | |
i = i - 1 | |
if a == b and len(a) >= 1: | |
print line, | |
z = z + 1 | |
a = [] | |
b = [] | |
print "There are %d palindromes!" % z |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment