Python Practice › String Programs › Program 18

Palindrome words in a string

EasyString Programs · 18 of 106

Write a Python program to get all palindrome words from a string.

Advertisement
Input
"Python efe language aakaa hellolleh"
Output
['efe', 'aakaa', 'hellolleh']

Approach

  1. Keep words equal to their reverse.

Solution

Python
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.

More string programs

← All 106 String Programs

Leave a Comment