tags:
- code
topic: List
difficulty: Intermediate
link: https://www.codewars.com/kata/554ca54ffa7d91b236000023
date: 2023-12-31
Problem
Given a list and a number, create a new list that contains each number of
list
at mostN
times, without reordering.
For example if the input number is
2
, and the input list is[1,2,3,1,2,1,2,3]
, you take[1,2,3,1,2]
, drop the next[1,2]
since this would lead to1
and2
being in the result3
times, and then take3
, which leads to[1,2,3,1,2,3]
.
With list
[20,37,20,21]
and number1
, the result would be[20,37,21]
.
def delete_nth(order,max_e):
s = []
for i in order:
if s.count(i) < max_e:
s.append(i)
return s