In this program, we will take a string as input and get all the palindrome words from the string
Steps to solve the program
- Take a string as input.
- Convert the string into a list using Split() and create an empty list.
- Use For loop to iterate over every of the list.
- Check if the word is palindrome or not, if yes then add that word to the empty list.
- Print the new list.
#Input string
string = "Python efe language aakaa hellolleh"
List = string.split(" ")
new_list = []
for val in List:
if val == val[::-1]:
new_list.append(val)
#Printing output
print(new_list)
Output :
['efe', 'aakaa', 'hellolleh']