So I know answering this will most likely take you off-site so if it’s too much of a hassle don’t bother.
The problem description is the link in the title.
my code is:
if __name__ == '__main__': my_names =  my_scores =  #creating lists to store the inputs, later going to zip them together. for _ in range(int(input())): name = input() score = float(input()) my_names.append(name) my_scores.append(score) #sorting the zip list to keep scores and names grouped. sorted_zip = sorted(zip(my_scores, my_names), key=lambda x: x) x =  y =  #unzipping the list so that the scores can be compared. Was unsure if I could # compare tuples. for i in sorted_zip: x.append(i) y.append(i) #locating second lowest score and printing the corresponding name. for i in range(len(x)+1): if x[i] < x[i+1]: for z in range(i+2,len(x)): if x[i+1] == x[z]: print(y[z]) print(y[i+1]) break #This is putrid code...
So I realize that this isn’t the most elegant code but I could use some assistance on figuring out why it fails the case where the input is:
3 Test1 52 Test2 53 Test3 53
For all other test cases it passes with flying colors. I’m assuming it has to do with the second nested loop and the fact that the list length is only 3 with the second lowest scores being the final two. I don’t know how to fix the indexing without receiving an index error