Python Practice › List Programs › Program 21

Is a list a palindrome?

EasyList Programs · 21 of 100

Write a Python program to check whether a list reads the same forwards and backwards.

Advertisement
Input
[1, 2, 3, 2, 1], [1, 2, 3]
Output
[1, 2, 3, 2, 1] True
[1, 2, 3] False

Approach

  1. Compare the list with its reverse.

Solution

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

More list programs

← All 100 List Programs

Leave a Comment