How to best write a Python function (check_list) to efficiently test if an element (x) occurs at least n times in a list (l
This shows another way of doing it.
Find if the element at that index is the same as the item you want to find.
def check_list(l, x, n):
_l = sorted(l)
try:
index_1 = _l.index(x)
return _l[index_1 + n - 1] == x
except IndexError:
return False