 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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 omit K length Rows
When it is required to omit K length rows, a simple iteration and the ‘len’ method along with ‘append’ method are used.
Example
Below is a demonstration of the same
my_list = [[41, 7], [8, 10, 12, 8], [10, 11], [6, 82, 10]] print("The list is :") print(my_list) my_k = 2 print("The value of K is ") print(my_k) my_result = [] for row in my_list: if len(row) != my_k : my_result.append(row) print("The resultant list is :") print(my_result)  Output
The list is : [[41, 7], [8, 10, 12, 8], [10, 11], [6, 82, 10]] The value of K is 2 The resultant list is : [[8, 10, 12, 8], [6, 82, 10]]
Explanation
- A list of list is defined and is displayed on the console. 
- A key values defined and is displayed on the console. 
- An empty dictionary is created. 
- The list is iterated over. 
- If the length of the specific list is not equal to key value, it is appended to the empty list. 
- This is the output that is displayed on the console. 
Advertisements
 