In this program, we will take a user input as a list and get palindrome numbers from a given list.
Palindrome numbers in a list:
Steps to solve the program
- Take a list as input and create an empty list.
- Calculate the reverse of each number from the given list using for and while loop.
- Check if the original number and reversed numbers are equal or not.
- if equal then add those reverse number to the empty list.
- Print the list to see the result.
#Input list
list1 = [121, 134, 354, 383, 892, 232]
list2 = []
for value in list1:
num = value
reverse=0
while num != 0:
digit = num%10
reverse = reverse*10 + digit
num //= 10
if reverse == value:
list2.append(value)
#Printing output
print(list2)
Output :
[121, 383, 232]
Related Articles
Python program to get a count of vowels in the given list.
Python program to get the list of prime numbers in a given list.
Python program to get a list with n elements removed from the left and right.
Python program to create a dictionary with two lists.
Python program to remove the duplicate item from the list using set.
Python program to insert a sublist into the list at a specific index.