Skip to content

Instantly share code, notes, and snippets.

@r14152
Created August 15, 2021 08:28
Show Gist options
  • Save r14152/8d272a1e23a5292cf0238c8e18a27eec to your computer and use it in GitHub Desktop.
Save r14152/8d272a1e23a5292cf0238c8e18a27eec to your computer and use it in GitHub Desktop.
NestedList from hackerrank
if __name__ == '__main__':
nestedList = []
for _ in range(int(input())):
name = input()
score = float(input())
nestedList.append([name,score])
#print(nestedList, name, score)
#sort the nested list based on the second digit
nestedList.sort(key = lambda x:x[1])
#print(nestedList)
firstNum = False
firstDigit = 0
secondDigit = 0
studentName = []
for x in nestedList:
if not firstNum:
firstDigit = x[1]
firstNum = True
continue
if firstDigit == x[1]:
continue
if (secondDigit == 0):
studentName.append(x[0])
secondDigit = x[1]
continue
if (x[1] > secondDigit):
break
studentName.append(x[0])
studentName.sort()
for name in studentName:
print(name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment