Don't try to copy the style of others . Shorten the code as long as you are able to understand that andalways remember that writing a loop in a single line will never improve the time complexity.
So if you are a beginner first be comfortable with all the underlying concepts and then move ahead...
if __name__ == '__main__':
first_names = []
second_names = []
first = float("inf")
second = float("inf")
for _ in range(int(input())):
name = input()
score = float(input())
if score < first:
second = first
second_names = first_names
first = score
first_names = []
first_names.append(name)
elif score == first:
first_names.append(name)
elif score < second:
second = score
second_names = []
second_names.append(name)
elif score == second:
second_names.append(name)
for name in sorted(second_names):
print(name)
더 깔끔하게
from collections import defaultdict
if __name__ == '__main__':
first = float("inf")
second = float("inf")
table = defaultdict(list)
for _ in range(int(input())):
name = input()
score = float(input())
table[score].append(name)
if score < first:
second = first
first = score
elif score < second and score != first:
second = score
for name in sorted(table[second]):
print(name)