Get all the palindrome words from the string

In this program, we will take a string as input and get all the palindrome words from the string

Steps to solve the program
  1. Take a string as input.
  2. Convert the string into a list using Split() and create an empty list.
  3. Use For loop to iterate over every of the list.
  4. Check if the word is palindrome or not, if yes then add that word to the empty list.
  5. 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']
				
			

replace the words “Java” with “Python” in the given string.

create a string with a given list of words.

Leave a Comment