Python - file lines - pallindrome
<p>I have been doing python tasks for learning and I came across this task where I have to read a file that includes few words and if a line is palindrome (same when written backwards: lol > lol)
so I tried with this code but It doesn't print anything on the terminal:</p>

<pre><code>with open("words.txt") as f:
    for line in f:
        if line == line[::-1]:
            print line
</code></pre>

<p>But if I print like this, without an if condition, it prints the words:</p>

<pre><code>with open("words.txt") as f:
    for line in f:
        print line
</code></pre>

<p>I wonder why It wont print the words that I've written in the file:</p>

<pre><code>sefes
kurwa
rawuk
lol
bollob
</code></pre>

<p>The last character of each <code>line</code> is a newline character ("\n"). You need to strip trailing newlines (<code>"foo\n".strip()</code>) before checking whether the line is a palindrome.</p>

python python-2.7 palindrome