I have a list of indexes:
[24, 175, 78, 80, 659, 126, 141, 149, 29, 158, 178, 179]
I want to know how to identify (and remove) which ones are out of sequence.
desired outcome:
[24, 78, 80, 126, 141, 149, 158, 178, 179]
As a human, I see that 175, 659, and 29 stand out, but am unsure of how to do this programmatically.
I have tried a pairwise comparison (a subset of the index returning the first value if sub_arr[0]
< sub_arr[1]
.
new_ls = []
def eval_adjacent(ls):
if ls[1] > ls[0]:
return ls[0]
for n, ele in enumerate(idx_ls[:-1]):
res = eval_adjacent(idx_ls[n:n+2])
if res:
new_ls.append(res)
However, if the integer is less than it should be, this won't work (29). Have thought about iterating in both directions but am starting to think this is not the way to go.
I think comparing it to sorted(ls) is potentially easier - but am not sure how to select the ones which are desirable (rejecting the remainder).
Can anyone point me in the right direction?