Why doesn't this code work?

I know this code is messy, but it is returning the correct answer. So why is it being marked wrong?

#Write your function here
def reversed_list(lst1, lst2):
  new1 = []
  for i in range(len(lst1)):
  	if i > 0:
  return new1 == lst2

#Uncomment the lines below when your function is done
print(reversed_list([1, 2, 3], [3, 2, 1]))
print(reversed_list([1, 5, 3], [3, 2, 1]))

Are you getting an error message? If so, what is it exactly?

Edit: I reset the exercise, and ran your code. I believe you likely received an ‘index out of range’ error. It appears that the SCT tests your code with empty lists: print(reversed_list([],[]). Your code does throw an error in that case due to this line: new1.append(lst1[0]). If lst1 is empty, lst1[0] doesn’t exist, and is therefore out of range.

1 Like

Hey thanks that actually makes sense to me! I appreciate it.

1 Like