Python – How can I write a python program to accept a List, and extract all elements whose frequency is greater than K? Please advise?
Sample I/O:
Input List:
[4, 6, 4, 3, 3, 4, 3, 4, 6, 6]
Input K:
2
Required Output : [4, 3, 6]
>Solution :
Use a list comprehension:
a = [4, 6, 4, 3, 3, 4, 3, 4, 6, 6]
k = 2
out = [i for i in set(a) if a.count(i) > k]