-
Notifications
You must be signed in to change notification settings - Fork 1
/
3_nestedlists.py
41 lines (28 loc) · 979 Bytes
/
3_nestedlists.py
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
# Solution to [Nested Lists](https://www.hackerrank.com/challenges/nested-list)
"""
I implement a naive solution. A better time complexity solution may:
1. Dynamically create the list a binary search
2. Returns elements with the second lowest value
or, alternatively, create a dictionary of score keys that track names of users with the second lowest score.
"""
if __name__ == '__main__':
## Create names
names = []
for _ in range(int(input())):
name = input()
score = float(input())
names.append((name, score))
## Sort list
names.sort(key = lambda x: (x[1], x[0]))
## Tracking vars
min_value = names[0][1]
flag_second_val = False
second_min_val = None
for n in names:
val = n[1]
if val == min_value:
continue
elif second_min_val is None:
second_min_val = val
if val == second_min_val:
print(n[0])