Python Practice › List Programs › Program 21
Is a list a palindrome?
Write a Python program to check whether a list reads the same forwards and backwards.
Input
[1, 2, 3, 2, 1], [1, 2, 3]
Output
[1, 2, 3, 2, 1] True [1, 2, 3] False
Approach
- Compare the list with its reverse.
Solution
for items in [[1, 2, 3, 2, 1], [1, 2, 3]]: print(items, items == items[::-1])Output
[1, 2, 3, 2, 1] True [1, 2, 3] False
Learn the concept
New to this topic? Read the lesson, then come back.