-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnestedLists.py
More file actions
41 lines (36 loc) · 1.18 KB
/
Copy pathnestedLists.py
File metadata and controls
41 lines (36 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/env python3
#
# hackerrank.com
# https://www.hackerrank.com/challenges/nested-list
#
# INPUT: first line N, number of students
# 2N subsequent lines describe ea student over 2 lines
# - line 1: student's name
# - line 2: grade
# Constraints:
# 2<= N <= 5
# there will always be one or more students having the second lowest grade
#
# OUTPUT: print the name(s) of any student(s) having the second lowest
# grade
# if there are multiple sutdents, order their names, alphabetically and
# print each one on a new line.
#
#
if __name__ == '__main__':
# A list for holding the students.
students = []
# Loop over each student putting their name and score into a
# list inside a list.
for _ in range(int(input())):
name = input()
score = float(input())
students.append([name, score])
# Find lowest.
# Find second lowest.
# Print those students with the second lowest.
lowest_grade = min(set([i[1] for i in students]))
next_lowest_grade = min(set([i[1]
for i in students if i[1] > lowest_grade]))
for name in sorted(i[0] for i in students if i[1] == next_lowest_grade):
print(name)