Lesson 25 of 34

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

9 min 30 XP

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

A lambda is a tiny one-line function. lambda x: x * 2 is the same as 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 பெரியதிலிருந்து சிறியதாக.

sorted(list, key=...) lets you choose what to sort by. reverse=True sorts from largest to smallest.

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-ஐ மாற்றும்.

sorted() returns a new list and leaves the original alone. list.sort() changes the list itself.

Challenge

+30 XP

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

students = [("Arun", 80), ("Priya", 95), ("Kavi", 70), ("Ravi", 88)]. Sort them with the highest marks first and print only the names, one per line.

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