Question:
Suppose you have a list:
- Delete every nth element.
- If the next nth element exceeds the list's length, modulate it.
- Do it till one element left.
Example:
a = [1, 2, 3, 4, 5, 6, 7, 8]
period = 3
for each iteration a must be:
a = [1, 2, 3, 4, 5, 6, 7, 8]
a = [1, 2, 4, 5, 6, 7, 8]
a = [1, 2, 4, 5, 7, 8]
a = [2, 4, 5, 7, 8]
a = [2, 4, 7, 8]
a = [4, 7, 8]
a = [4, 7]
a = [7]
I must know.
I'm editing this because I forgot to add what I did and not succeed.
Here my attempt:
a = [1, 2, 3, 4, 5, 6, 7, 8]
periyot = 3
for it, i in enumerate(range(periyot, periyot * len(a), periyot), start=1):
index = (i - it) % len(a)
del a[index % len(a)]
print(a)
Which returns:
[1, 2, 4, 5, 6, 7, 8]
[1, 2, 4, 5, 7, 8]
[2, 4, 5, 7, 8]
[2, 4, 5, 8] # I'm off from here
[2, 4, 8]
[4, 8]
[8]