Given array of integers, remove each kth
element from it.
Example
For inputArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
and k = 3
, the output should beextractEachKth(inputArray, k) = [1, 2, 4, 5, 7, 8, 10]
.
我的解答:
def extractEachKth(inputArray, k):
return [i for i in inputArray if i not in inputArray[k - 1::k]]
def extractEachKth(inputArray, k):
del inputArray[k-1::k]
return inputArray
膜拜大佬