- 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 extract Mono-digit elements
When it is required to extract mono-digit elements, list comprehension and the ‘all operator are used.
Below is a demonstration of the same −
my_list = [863, 1, 463, "pyt", 782, 241, "is", 639, 4, "fun"] print("The list is :") print(my_list) my_result = [index for index in my_list if all(str(element) == str(index) for element in str(index))] print("The result is :") print(my_result)
The list is : [863, 1, 463, 'pyt', 782, 241, 'is', 639, 4, 'fun'] The result is : [1, 4]
A list is defined and displayed on the console.
A list comprehension is used to iterate over the list, and every element is converted to a list and compared with the zeroth element.
This is converted to a list.
This is assigned to a variable.
This is the output that is displayed on the console.
- Extract tuples having K digit elements in Python
- Python program to extract rows with common difference elements
- Python Program to Extract Elements from a List in a Set
- Python – Reform K digit elements
- Python Program to Extract Rows of a matrix with Even frequency Elements
- Python – Extract String elements from Mixed Matrix
- Python – Extract elements from Ranges in List
- Python – Extract tuples with elements in Range
- Program to extract frames using OpenCV in Python?
- Python program to extract Keywords from a list
- How to extract the digit part from the string in MySQL?
- Python – Extract elements with equal frequency as value
- Python – Sort by a particular digit count in elements
- Extract Unique dictionary values in Python Program
- Program to find super digit of a number in Python