Skip to content

Instantly share code, notes, and snippets.

@amulyakashyap09
Created December 31, 2017 12:21
Show Gist options
  • Save amulyakashyap09/8fb5fdfbf059cdf59709d84a4e5585c0 to your computer and use it in GitHub Desktop.
Save amulyakashyap09/8fb5fdfbf059cdf59709d84a4e5585c0 to your computer and use it in GitHub Desktop.
Print second lowest values from nested lists | hackerrank
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