Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for When "k" is Enough! by zongareight
from typing import Iterable
def remove_after_kth(items: list, k: int) -> Iterable:
counter, result = {}, []
for i in items:
if i not in counter:
counter[i] = 0
counter[i] += 1
if counter[i] <= k:
result += [i]
return result
Oct. 20, 2022