
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
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.
- Related Articles
- Python program to remove K length words in String
- Python Program to Group Strings by K length Using Suffix
- Python Program to get K length groups with given summation
- Program to find maximum length of k ribbons of same length in Python
- Program to find k-length paths on a binary tree in Python
- Python Program to test whether the length of rows are in increasing order
- Python program to print Rows where all its Elements’ frequency is greater than K
- Python – Rows with K string in Matrix
- Python - Sort rows by Frequency of K
- Program to find min length of run-length encoding after removing at most k characters in Python
- Program to find length of longest substring which contains k distinct characters in Python
- Python – Extract rows with Even length strings
- Python Program that prints the rows of a given length from a matrix
- Program to find length of longest set of 1s by flipping k bits in Python
- Program to find lexicographically smallest lowercase string of length k and distance n in Python

Advertisements