Created
February 14, 2015 19:30
-
-
Save ChanChar/533b29e4f51f2c2bdd5e to your computer and use it in GitHub Desktop.
2/14/2015 Solve Saturday Solutions
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
# Link: http://www.codeabbey.com/index/task_view/palindromes | |
# Outline: | |
# 1. Find the number of cases that will be in the problem. | |
# 2. For each case: | |
# 3. Either create a string or find a list of only letters | |
# 4. Remove case-sensitivity | |
# 5. Compare the string/list to its reversed version | |
# 6. Print "Y" if the comparisons are equal and "N" otherwise. | |
# 7. Run and check. | |
# Methods covered: | |
# A. Filtering out non alphabetic characters | |
# B. Reversing a string/array | |
# C. Comparing a string/array to its reversed | |
# Step 5. | |
def is_palindrome(phrase): | |
# Methods B/C | |
return phrase == phrase[::-1] | |
# Step 1. | |
number_of_cases = int(input()) | |
# Step 2. | |
for case in range(number_of_cases): | |
# Method A; Steps 3-6 (is_palindrome() - Step 5) | |
letters = [letter.lower() for letter in list(input()) if letter.isalpha()] | |
if is_palindrome(letters): | |
print("Y", end=' ') | |
else: | |
print("N", end=' ') | |
# string.lower() - Converts all alphabetic characters in string to lowercase | |
# list(string) - Converts string into a list of single characters | |
# string.isalpha() - Returns true is the string is alphabetic and false otherwise | |
# is_palindrome(phrase) - Checks to see if the phrase is a palindrome |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment