Created
December 31, 2017 12:21
-
-
Save amulyakashyap09/8fb5fdfbf059cdf59709d84a4e5585c0 to your computer and use it in GitHub Desktop.
Print second lowest values from nested lists | hackerrank
This file contains 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
from operator import itemgetter | |
if __name__ == '__main__': | |
students=[] | |
lowest_score=0; | |
for _ in range(int(input())): | |
name = input() | |
score = float(input()) | |
students.append([name, score]) | |
#get minimum value of nested list | |
mn = min(students, key=itemgetter(1))[1] | |
#remove minimum value from nested list | |
filtered = [x for x in students if x[1] != mn] | |
#get minimum value of nested list again (now it'll be second min as min. value has been already removed earlier) | |
mn_fil = min(filtered,key=itemgetter(1))[1] | |
#now print out the all second lowest values | |
out = [x[0] for x in filtered if x[1] == mn_fil] | |
out.sort() | |
for x in out: | |
print(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment