Return error on loop code challenge 5/11

I’m trying to figure out why I get this error:

File “”, line 7
return new_listPreformatted text
SyntaxError: ‘return’ outside function

for this code:

#Write your function here

def odd_indices(lst):

new_list =

for index in range(1, len(lst), 2):


return new_list

the return position lines up exactly as it does in the “solution” code and seems to me to be properly indented.

Can you point me in the right direction on how to trouble shoot the indent error for return new_list?

AHHH not sure why this wont indent on the preview vs when i type it into the POST! SMFH!

Hello! It’ll be due to the indentation of return. Make sure it’s indented inline with the for of the for loop:

def some_function():
  |for i in something_else:
  | print("Yay, doing something!")
  |return "This is correctly indented to return after the for loop"
#See, the bars line up

To format code correctly (and preserve whitespace), see this thread.

1 Like

Thanks codeneutrino, that was a good point in the right direction!
I needed to indent the for loop from the def function, and as you mentioned, the return needed to be on the same inline as the for loop.
For loops are one of the most challenging aspect for me, thanks!

1 Like