1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Nested list hacker rank quetion [closed]

Discussão em 'Python' iniciado por Stack, Setembro 18, 2025.

  1. Stack

    Stack Membro Participativo

    My program in hacker rank keeps on giving me IndexError: list index out of range for second_score = sorted(set([item[1] for item in nested_list]))[1] where as it runs perfectly for visula code.

    The code:

    if __name__ == '__main__':
    nested_list = []
    for _ in range(int(input())):
    name = input()
    score = float(input())
    nested_list.append([name,score])

    nested_list.sort(key= lambda x:[x[1],x[0]])
    second_score = sorted(set([item[1] for item in nested_list]))[1]

    list=[]
    for i in nested_list:
    if i[1] == second_score:
    list.append(i[0])

    list.sort()
    for j in list:
    print(j)

    Continue reading...

Compartilhe esta Página