here is my code for hackerrank nested list problem in python problem link:https://www.hackerrank.com/challenges/nested-list/problem?isFullScreen=true
code:
def sort(sub_li):
return(sorted(sub_li, key = lambda x: x[1]))
if __name__ == '__main__':
x=int(input ())
stu=[]
record=[]
for i in range(0,x):
stu.append(input())
stu.append(input())
record.append(stu)
stu = []
namelist = []
sortedrecord = sort(record)
print(sortedrecord)
value = 0
for i,j in sortedrecord:
if j>sortedrecord[0][1]:
value = j
break
for i,j in sortedrecord:
if j==value:
namelist.append(i)
namelist.sort()
for i in namelist:
print(i)
problem is that the sort fuction is not sorting properly when it has a score of 10
sample input:
4
Shadab
8
Varun
8.9
Sarvesh
9.5
Harsh
10
output:
[['Harsh', '10'], ['Shadab', '8'], ['Varun', '8.9'], ['Sarvesh', '9.5']]
Shadab
note: i have tried alternative sorting ways ,but the condition remains the same.
In the lexicographic order,
10comes befor8, because1is before8You need to convert to
floatto get it work like you expectat input
or at use