Python Practice › String Programs › Program 18
Palindrome words in a string
Write a Python program to get all palindrome words from a string.
Input
"Python efe language aakaa hellolleh"
Output
['efe', 'aakaa', 'hellolleh']
Approach
- Keep words equal to their reverse.
Solution
text = "Python efe language aakaa hellolleh"print([w for w in text.split() if w.lower() == w.lower()[::-1]])Output
['efe', 'aakaa', 'hellolleh']
Learn the concept
New to this topic? Read the lesson, then come back.