That line does not test the index, but the value at that index. It should be checking if the index is odd, and capture the value, whatever it is, at that index.
So, I already apologize before hand if this question is super dumb since I’m 7 days into coding. But I figured out this way to solve this exercise and it does give the appropriate result, but prints an error (local variable ‘new_lst’ referenced before assignment). I don’t understand why that should be a problem, since the end result is the one desired. This is my piece of code:
def odd_indices(lst):
substract = len(lst)
for index in range(1, len(lst), 2):
lst.append(lst[index])
new_lst = lst[substract:]
return new_lst
print(odd_indices([4, 3, 7, 10, 11, -2]))
I’ve seen the solution now and it is more elegant and see it is a better way to have that output, but still don’t know why the first one should be wrong.
Would anybody be nice enough to enlighten me. Thanks a lot!!