I've been writing some code that involves inserting random characters into a list, and then removing those characters. Imagine you have a string:
['x', 'x', 'x', 'x', 'x', 'x', 'x', 'x']
With this as an input, you get this as an output:
['x', 'x', 'a', 'r', 'x', 'x', 't', 'q', 'x', 'x' 'j', 'z', 'x', 'x']
I have this code written. I tried this for removing those random characters:
iterations = 0
removal = 0
for s in my_list:
if iterations % 3 == 0:
removal = 0
for letters in range(2):
del my_list[removal + iterations]
removal += 1
iterations += 1
This just removes some of them, and I can't really figure out the pattern. The idea is that this would be able to take out, say, five characters every eight iterations through a list. Or any number of characters every any number iterations.