Lesson 25 of 34

lambda, sorted() மற்றும் key

9 min 30 XP

lambda என்பது ஒரே வரியில் எழுதும் சிறிய function. lambda x: x * 2 என்பது def double(x): return x * 2 போன்றதே.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

sorted(list, key=...) மூலம் எந்த அடிப்படையில் வரிசைப்படுத்த வேண்டும் என்று சொல்லலாம். reverse=True பெரியதிலிருந்து சிறியதாக.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

sorted() புதிய list தரும்; பழைய list மாறாது. list.sort() அதே list-ஐ மாற்றும்.

Challenge

+30 XP

students = [("Arun", 80), ("Priya", 95), ("Kavi", 70), ("Ravi", 88)]. மதிப்பெண் அதிகமானவர் முதலில் வரும்படி வரிசைப்படுத்தி, பெயர்களை மட்டும் ஒவ்வொரு வரியிலும் print செய்யுங்கள்.

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.