- 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 – Filter rows with only Alphabets from List of Lists
When it is required to filter the rows that contains only alphabets in a list of lists, the list is iterated over and the ‘isalpha’ method is used to check if an alphabet is present or not.
Below is a demonstration of the same
my_list = [["python", "is", "best"], ["abc123", "good"],["abc def ghij"], ["abc2", "gpqr"]] print("The list is :") print(my_list) my_result = [sub for sub in my_list if all(element.isalpha() for element in sub)] print("The result is :") print(my_result)
The list is : [['python', 'is', 'best'], ['abc123', 'good'], ['abc def ghij'], ['abc2', 'gpqr']] The result is : [['python', 'is', 'best']]
A list of list elements is defined that contains string values.
This is displayed on the console.
The elements are iterated over and checked to see if they are alphabets.
This is done using the ‘isalpha’ method.
The results are assigned to a variable.
This variable is displayed as output on the console.
- Python - Column deletion from list of lists
- Python - Ways to initialize list with alphabets
- Python – Filter rows with required elements
- Python – Filter Rows with Range Elements
- Python – Filter rows with Elements as Multiple of K
- Python - Filter even values from a list
- Python – Filter Sorted Rows
- Get positive elements from given list of lists in Python
- Python – Filter immutable rows representing Dictionary Keys from Matrix
- Convert list into list of lists in Python
- Python - Convert List of lists to List of Sets
- Filter the rows – Python Pandas
- Python – Filter all uppercase characters from given list of tuples
- Python Program to Filter Rows with a specific Pair Sum
- Filter Tuples by Kth element from List in Python