We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Solution with explanation:
First sort the nested lists in aplhabetical order. Make a separate set for marks ,remove duplicate values and sort it. The second element is the second lowest marks so now print the names that have second lowest marks.
if name == 'main':
stud=[]
for _ in range(int(input())):
name = input()
score = float(input())
stud.append([name,score])
# sort in alphabetical order of name
_stud=sorted(stud,key= lambda x: x[0])
marks=[] #stores marks
for i in range(len(_stud)):
marks.append(_stud[i][1])
#removes duplicate values and arrange in descending order
marks=list(sorted(set(marks)))
answer=marks[1]
#print students with second lowest marks
for i in range(len(_stud)):
if(_stud[i][1]==answer):
print(_stud[i][0])
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Nested Lists
You are viewing a single comment's thread. Return to all comments →
Solution with explanation: First sort the nested lists in aplhabetical order. Make a separate set for marks ,remove duplicate values and sort it. The second element is the second lowest marks so now print the names that have second lowest marks.
if name == 'main': stud=[] for _ in range(int(input())): name = input() score = float(input()) stud.append([name,score])