So I have a problem where I need to remove the integers that occur more than n times from the list. This is giving me an error that remove(x) doesn't exist in the list. Help!
def answer1(data, n):
    for i in range(len(data)):
        item = 0
        if data.count(i) > n:
            item = i
            for k in range(len(data)):
                data.remove(item)
    print(data)
data = [1, 2, 3, 1, 1, 2, 2, 3, 4 ,5]
answer1(data, 2)
 
     
    