Created
August 15, 2021 08:28
-
-
Save r14152/8d272a1e23a5292cf0238c8e18a27eec to your computer and use it in GitHub Desktop.
NestedList from hackerrank
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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