In this Python list program, we will take a user input as a list and get the list of palindrome strings from the given list with the hep of the below-given steps.
List of palindrome strings:
Steps to solve the program
- Take a list of strings as input and create an empty string to create a list of palindrome strings.
- Use for loop to iterate over each string from the list
- During iteration check, if the string is equal to its reverse order.
- If yes then add that string to the empty list.
- Print the list to see the result.
#Input lists
list1 = ["data", "python", "oko", "test", "ete"]
list2 = []
for value in list1:
new = value[::-1]
if new == value:
list2.append(value)
#Printing output
print(list2)
Output :
['oko', 'ete']
Related Articles
Python program to flatten a given nested list structure.
Python program to convert tuples in the list into a sublist.
Python program to create a dictionary from a sublist in a given list.
Python program to replace ‘Java’ with ‘Python’ from the given list.
Python program to convert the 3rd character of each word to a capital case from the given list.
Python program to remove the 2nd character of each word from a given list.