Palindrome

From CleanPosts

Jump to: navigation, search

Find all palindromic words in a file

#!/usr/bin/python

def words(fileobj):
    for line in fileobj:
        for word in line.split():
            yield word

with open("words.txt") as wordfile:
     wordgen = words(wordfile)
     for word in wordgen:
         if word == word[::-1]:
              print(word),

Image:Screenshot from 2021-07-17 08-39-59.png

Personal tools
Strangers In Paradise