Python Practice › List Programs › Program 80

Palindrome numbers in a list

EasyList Programs · 80 of 100

Write a Python program to get the palindrome numbers from a list.

Advertisement
Input
[121, 134, 354, 383, 892, 232]
Output
[121, 383, 232]

Approach

  1. Keep numbers equal to their reverse.

Solution

Python
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.

More list programs

← All 100 List Programs

Leave a Comment