I created a list (which is sorted):
indexlist = [0, 7, 8, 12, 19, 25, 26, 27, 29, 30, 31, 33]
I want to extract numbers from this list that are in at least five places from each other and enter them in another list. It scares. This is an example of how I want the output:
outlist = [0, 7, 19, 25, 31]
As you can see, none of the numbers is within 5 of each other.
I tried this method:
for index2 in range(0, len(indexlist) - 1): if indexlist[index2 + 1] > indexlist[index2] + 5: outlist.append(indexlist[index2])
However, this gives me this result:
outlist = [0, 12, 19]
Of course, the numbers are at least 5, but I miss some of the necessary values.
Any ideas on how I can accomplish this task?
source share