Okay so for context the variable arr in this problem is just a space separated list of random numbers and I am trying to select the second largest value in the list of random numbers. My code is:
my_list =  for i in arr: my_list.append(i) my_list.sort(reverse=True) for x in range(len(my_list)): if my_list[x] != my_list[x+1]: print(my_list[x+1])
I get the error “IndexError: list index out of range” but I don’t see how.
My second loop I should be looping through a list that starts at zero and ends at the length of the original array minus one. The proceeding if statement should catch the first instance where consecutive numbers are not equal and, because I ordered the list, it should also be the second largest value.
Can someone explain the error I am getting?