I am a beginner in python. This is the Nested Lists problem from HaackerRank.
Given the names and grades for each student in a Physics class of N students, store them in a nested list and print the name(s) of any student(s) having the second lowest grade.
Note: If there are multiple students with the same grade, order their names alphabetically and print each name on a new line.
I want to improve my code with better functions available in python and I want to decrease lines of code.
if __name__ == '__main__': scorecard =  for _ in range(int(input())): name = input() score = float(input()) scorecard.append([name, score]) scorecard.sort(key = lambda x:x) names =  lowest_score = scorecard second_lowest = 0 for i in range(len(scorecard)): if scorecard[i] > lowest_score and second_lowest == 0: second_lowest = scorecard[i] if second_lowest != 0 and scorecard[i] == second_lowest: names.append(scorecard[i]) names.sort() for name in names: print(name)