Python program to check if given value occurs atleast k times
Given a list and some value (let’s say it N), write a Python program to check if the given value occurs atleast k-times in that list.
We can use list comprehension to deal with this problem. We can add each occurrence of given value and check if it is greater than or equal to k. If the value returned is True, then set the flag to 1, else 0.
Below is the Python implementation –
# Python program to check if given # value occurs atleast k times test_list = [1, 3, 5, 5, 4, 5] # printing original list print ("The original list is : " + str(test_list)) # value to be checked val = 5 # initializing k k = 3 # using sum() + list comprehension # checking occurrences res = 0res = sum([1 for i in test_list if i == val]) >= k if res == 1 : res = Trueelse : res = False # printing result print ("%d occur atleast %d times ? :" %(val, k) + str(res)) |
chevron_right
filter_none
Output:
The original list is : [1, 3, 5, 5, 4, 5] 5 occur atleast 3 times ? :True
Recommended Posts:
- Python | Check if k occurs atleast n times in a list
- Python Program to Find the Number Occurring Odd Number of Times
- Python program to check whether a number is Prime or not
- Python Program to Check Prime Number
- Python Program to check if given array is Monotonic
- Python program to check if given string is pangram
- Python program to check if a string is palindrome or not
- Python program to check if a given string is Keyword or not
- Python Program to check Armstrong Number
- Python Program for Check if count of divisors is even or odd
- Python program to check the validity of a Password
- Python program to check if string is empty or not
- Python Program for Check if all digits of a number divide it
- Python program to check if given string is vowel Palindrome
- Python program to check if number is palindrome (one-liner)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



