Python Practice › List Programs › Program 80
Palindrome numbers in a list
Write a Python program to get the palindrome numbers from a list.
Input
[121, 134, 354, 383, 892, 232]
Output
[121, 383, 232]
Approach
- Keep numbers equal to their reverse.
Solution
numbers = [121, 134, 354, 383, 892, 232]print([n for n in numbers if str(n) == str(n)[::-1]])Output
[121, 383, 232]
Note
383 is a palindrome too; the original sample answer listed 282 instead.
Learn the concept
New to this topic? Read the lesson, then come back.