- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 print Rows where all its Elements’ frequency is greater than K
When it is required to print rows where all its elements’ frequency is greater than K, a method is defined that takes two parameters, and uses ‘all’ operator and iteration to give the result.
Below is a demonstration of the same −
Example
def frequency_greater_K(row, K) : return all(row.count(element) > K for element in row) my_list = [[11, 11, 32, 43, 12, 23], [42, 14, 55, 62, 16], [11, 11, 11, 11], [42, 54, 61, 18]] print("The tuple is :") print(my_list) K = 1 print("The value of K is :") print(K) my_result = [row for row in my_list if frequency_greater_K(row, K)] print("The result is :") print(my_result)
Output
The tuple is : [[11, 11, 32, 43, 12, 23], [42, 14, 55, 62, 16], [11, 11, 11, 11], [42, 54, 61, 18]] The value of K is : 1 The result is : [[11, 11, 11, 11]]
Explanation
A method named ‘frequency_greater_K’ is defined that takes row and K value as parameters, and returns the comparison between element count and key as output.
A list of list is defined and displayed on the console.
A list comprehension is used to iterate over the list, and the method is called on every list.
This result is assigned to a variable.
This is the output that is displayed on the console.
- Related Articles
- Count subarrays with all elements greater than K in C++
- Program to find number not greater than n where all digits are non-decreasing in python
- Python – Remove characters greater than K
- Program to find k where k elements have value at least k in Python
- Find the Number of segments where all elements are greater than X using C++
- Python - Sort rows by Frequency of K
- Python Program to Extract Rows of a matrix with Even frequency Elements
- Python Indices of numbers greater than K
- Python – Average of digit greater than K
- Python – Filter Tuples Product greater than K
- Count of elements whose absolute difference with the sum of all the other elements is greater than k in C++
- Python – Sort Matrix by Number of elements greater than its previous element
- Find smallest element greater than K in Python
- Python - Consecutive Ranges of K greater than N
- Python – Remove Tuples with difference greater than K

Advertisements