Second largest · השני בגודלו
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].
השנייה הגדולה ביותר
חזר הערך השני בגודלו המובדל. כפילויות של המקסימום לא נספרות, אז [5, 5, 4] מחזירה 4, לא 5.
דרך נקייה: הסר כפילויות עם set(...), סמן את התוצאה, וחזר על הערך אחד לפני האחרון עם [-2].
Write second_largest(xs) that returns the second-largest distinct value in xs. You may assume there are at least two distinct values. · כתוב פונקציה second_largest(xs) שמחזירה את הערך השני בגודלו היחיד ב-xs. ניתן להניח שישנם לפחות שני ערכים ייחודיים.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.