forked from minaevd/hackerrank-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnested_lists.py
More file actions
executable file
·48 lines (34 loc) · 1.08 KB
/
Copy pathnested_lists.py
File metadata and controls
executable file
·48 lines (34 loc) · 1.08 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
42
43
44
45
46
"""
Title: Nested Lists
Description: Given the names and grades for each student in a Physics class of
students, store them in a nested list and print the name(s) of any student(s)
having the second lowest grade.
Note: If there are multiple students with the same grade, order their names
alphabetically and print each name on a new line.
"""
import sys
N = int(raw_input())
first_names = []
second_names = []
first = second = sys.maxint
for i in range(N):
name = str(raw_input())
grade = float(raw_input())
# If current element is smaller than first then
# update both first and second
if grade < first:
second = first
first = grade
second_names = first_names
first_names = [name]
# If grade is in between first and second then
# update second
elif (grade == first):
first_names.append(name)
elif (grade < second):
second = grade
second_names = [name]
elif (grade == second):
second_names.append(name)
# print '--- --- --- --- ---'
print "\n".join(sorted(second_names))