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 –
The original list is : [1, 3, 5, 5, 4, 5] 5 occur atleast 3 times ? :True
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.