Created
June 9, 2021 02:57
-
-
Save joan0fsnark/d0ec5e2670583b9abc34bebf7b2f58b7 to your computer and use it in GitHub Desktop.
Find palindromes in list of words
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
list = ['radar', 'racecar', 'grumble'] | |
for word in list: | |
palindrome = True | |
start = 0 | |
end = len(word) - 1 # pos of last letter | |
while start < end: | |
if word[start] != word[end]: | |
print(f"Not a palindrome: {word}") | |
palindrome = False | |
break | |
start = start + 1 | |
end = end - 1 | |
if palindrome: | |
print(f"Palindrome: {word}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment