- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to Remove Palindromic Elements from a List
When it is required to remove palindromic elements from a list, list comprehension and the ‘not’ operator are used.
Below is a demonstration of the same
my_list = [56, 78, 12, 32, 4,8, 9, 100, 11] print("The list is : ") print(my_list) my_result = [elem for elem in my_list if int(str(elem)[::-1]) not in my_list] print("The result is : " ) print(my_result)
The list is : [56, 78, 12, 32, 4, 8, 9, 100, 11] The result is : [56, 78, 12, 32, 100]
A list is defined and displayed on the console.
A list comprehension is used to iterate over the list, and convert the element to string first and then to an integer and reverse it.
It is checked to see that the element is not in the list.
This is assigned to a variable.
This is displayed as output on the console.
- Python program to remove Duplicates elements from a List?
- Python program to remove duplicate elements from a Circular Linked List
- C# program to remove duplicate elements from a List
- Java program to remove duplicates elements from a List
- Python program to remove duplicate elements from a Doubly Linked List\n
- Python program to remove elements at Indices in List
- Python prorgam to remove duplicate elements index from other list
- Python Program to Remove First Diagonal Elements from a Square Matrix
- Python program to find N largest elements from a list
- Python Program to Extract Elements from a List in a Set
- Java Program to Remove a Sublist from a List
- Python | Remove empty tuples from a list
- Python - Ways to remove duplicates from list
- Remove a range of elements from the List in C#