In this HackerRank Nested Lists problem, we have given the names and grades for each student in a class of N students, store them in a nested list and print the name(s) of any student(s) having the second-lowest grade.

HackerRank Nested Lists in python problem solution

HackerRank Nested Lists in python problem solution

# we store the name and the mark associated.
# Then we take all the differents marks, removing the
# duplicates ones. We sort these values, and for the 
# second value, we print every names related, in ascending 
# order

marks = {}
n = input()
for x in range(n):
    name = raw_input()
    mark = input()
    
    if mark in marks:
        marks[mark].append(name)
    else:
        marks[mark] = [name]
        
all_marks = list(set(marks.keys()))
all_marks.sort()
names_ordered = marks[all_marks[1]]
names_ordered.sort()

for name in names_ordered:
    print name

Second solution

from operator import itemgetter

n = int(input())
students = []
for n in range(n):
    students.append([input(), float(input())])

lowest = sorted(set(map(itemgetter(1), students)))[1]
for student in sorted(filter(lambda l: l[1] == lowest, students)):
    print(student[0])