Odd Incides - Python Codecademy exercise -


#1

Hello there :slight_smile:
I am going through the Python course and I have a question regarding the exercise:
Create a function named odd_indices that has one parameter named lst . The function should create a new empty list and add every element from lst that has an odd index. The function should then return this new list.

I wrote the following code (which of course doesn’t work). My question is: why?

def odd_indices(lst):
odd_indices_list = []
for lst[i] in lst if i%2 == 0:
odd_indices_list.append(lst[i])
return odd_indices_list


#2

you are doing too much on one line here:

for lst[i] in lst if i%2 == 0:

the for loop and if condition should be two separate lines.

To get the indices value in python, use range()