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. · اضغط تشغيل لرؤية المخرجات هنا.