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 | Check if any element occurs n times in given list
- Python - Test if K occurs N consecutive times
- Python - Test if Substring occurs in specific position
- Python | Add similar value multiple times in list
- Python Program to Find the Number Occurring Odd Number of Times
- Python program to search for the minimum element occurring consecutively n times in a matrix
- Python | Check if all the values in a list that are greater than a given value
- Python | Check if all the values in a list are less than a given value
- Python - Extract ith Key's Value of K's Maximum value dictionary
- Python Program for How to check if a given number is Fibonacci number?
- Python List Equality | Program to check if two given matrices are identical
- Python Program to check if given array is Monotonic
- Python program to check if given string is vowel Palindrome
- Python program to check if given string is pangram
- Python program to check if a given string is Keyword or not
- Python program to check if the given string is IPv4 or IPv6 or Invalid
- Python | Repeat each element K times in list
- Python | Remove elements of list that are repeated less than k times
- Python | Repeating tuples N times
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.

