46 Python Problems

From http://www.ling.gu.se/~lager/python_exercises.html

Files Code and Result

poblem19.py

problem1.py

problem2.py

problem3.py

problem4.py

problem5.py

problem6.py

problem7.py

problem8.py

problem9.py

problem10.py

problem11.py

problem12.py

problem13.py

problem14.py

problem15.py

problem16.py

problem17.py

problem18.py

problem20.py

problem21.py

problem22.py

problem23.py

problem24.py

problem25.py

problem26.py

problem27.py

problem28.py

problem29.py

problem30.py

problem31.py

problem32.py

problem33.py

problem34.py

problem36.py

problem37.py

problem38.py

problem42.py

problem43.py

problem44.py

problem45.py

problem46.py

problem32.py

# requires palindrome.txt

def is_phrase_palindrome(str):
            '''(str) -> str
            return true if palindrome
            '''
            filtered_str = ''
            for letter in str:
                    if letter.isalpha():
                            filtered_str += letter
            str = filtered_str.lower()

            reverse_str = str[:: -1]
            half_len =len(str) // 2
            r_str = ''
            f_str =''
            for x in range(0, half_len):
                    r_str += reverse_str[x]
            for y in range(0, half_len):
                    f_str += str[y]

            return  r_str == f_str



def palindrome_printer():
            f = open('palindrome.txt', 'r')
            for line in f:
                    line = line.strip('\n')
                    if is_phrase_palindrome(line):
                            print(line)


ans = palindrome_printer()
print(ans)

Result

Sore was I ere I saw Eros.
A man, a plan, a canal -- Panama
Never a foot too far, even.
Euston saw I was not Sue.
Live on evasions? No, I save no evil.
Red Roses run no risk, sir, on nurses order.
Salisbury moor, sir, is roomy. Rub Silas.
Marge, let's "went." I await news telegram.
A new order began, a more Roman age bred Rowena.
I, man, am regal; a German am I.
Tracy, no panic in a pony-cart.
Egad! Loretta has Adams as mad as a hatter. Old age!
Eve, mad Adam, Eve!
Resume so pacific a pose, muser.
Marge let a moody baby doom a telegram.
None