- 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 – Rows with all List elements
When it is required to give the rows with all list elements, a flag value, a simple iteration and the ‘append’ method is used.
Below is a demonstration of the same
my_list = [[8, 6, 3, 2], [1, 6], [2, 1,7], [8, 1, 2]] print("The list is :") print(my_list) sub_list = [1, 2] result =  for row in my_list: flag = True for element in sub_list: if element not in row: flag = False if flag: result.append(row) print("The resultant list is :") print(result)
The list is : [[8, 6, 3, 2], [1, 6], [2, 1, 7], [8, 1, 2]] The resultant list is : [[2, 1, 7], [8, 1, 2]]
A list of list is defined and is displayed on the console.
Another list with integer values is defined.
Another empty list is defined.
The list of list is iterated over and a flag value is set to ‘True’.
If the element present in the integer list is not present in the list, the flag value is set to ‘False’.
In the end, depending on the flag value, the output is determined.
If the value of flag is ‘True’, the element is appended to the empty list.
This is displayed as output on the console.
- Python – Filter rows with required elements
- Python – Filter Rows with Range Elements
- Find all elements count in list in Python
- Python – Combine list with other list elements
- Accessing all elements at given Python list of indexes
- Check if list contains all unique elements in Python
- List consisting of all the alternate elements in Python
- Python program to extract rows with common difference elements
- Find distinct elements common to all rows of a matrix in Python
- Python - Check if all elements in a List are same
- Python - Check if all elements in a list are identical
- Python – Filter tuple with all same elements
- Python – Filter rows with Elements as Multiple of K
- Python – Strings with all given List characters
- Selects all elements with CSS