Palin

Find all palindromic words in a file

#!/usr/bin/python3
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, end=" ")
    print()

Unknown's avatar

About Linuxgal

Need a spiritual home? Consider joining us at Mary Queen of the Universe Latter-day Buddhislamic Free Will Christian UFO Synagogue of Vishnu
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a comment