Second largest · Segundo maior
Second largest
Return the second-biggest distinct value. Duplicates of the maximum don't count, so [5, 5, 4] gives 4, not 5.
One clean route: drop duplicates with set(...), sort the result, and take the value one in from the end with [-2].
Segundo maior
Devolva o valor segundo maior distinto. Duplicatas do máximo não contam, então [5, 5, 4] dá 4, não 5.
Uma rota limpa: remova duplicatas com set(...), ordene o resultado e pegue o valor um antes do fim com [-2].
Write second_largest(xs) that returns the second-largest distinct value in xs. You may assume there are at least two distinct values. · Escreva second_largest(xs) que retorne o segundo maior valor distinto em xs. Você pode assumir que há pelo menos dois valores distintos.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.