Hacker Rank Nested List

Viewed 28

I'm not understanding the syntax of the following. Can someone explain what is going on in the segment of code?

if score in dic:
    
    dic[score].append(name)

    else:

        dic[score] = [name]

This is the question:

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.

The full answer to the question is below.

dic = {}

l = []

if name == 'main':

for _ in range(int(input())):
    name = input()
    score = float(input())
    if score in dic:
        dic[score].append(name)
    else:
        dic[score] = [name]
    if core not in l:
        l.append(score)
    m = min(l)
    dic[m].sort()
    for i in dic[m]:
        print(i)
0 Answers
Related