Q:

how to print lines in a txt which fulfills certain condition with python?

def palindrome_filter(file_name):
    file=open('text_1.txt','r')
    for line in file:
        line=line.rstrip()
        if (is_palindrome(line)):
            print(line)
    file.close()
palindrome_filter('text_1.txt')

Above are the codes that I wrote. I actually want python to print the certain line which is a palindrome, but it keeps printing true or false instead. I wonder what's wrong with my code. (function to determine whether a line is palindrome is texted, it is correct.)

A:

Your solution might be:
def palindrome_filter(file_name):
    file=open('text_1.txt','r')
    for line in file:
        line = line.rstrip()
        if line == line[::-1]:
            print(line)
    file.close()

