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=...) എന്തിനെ അടിസ്ഥാനമാക്കി sort ചെയ്യണമെന്ന് തിരഞ്ഞെടുക്കാൻ അനുവദിക്കുന്നു. reverse=True വലുതിൽ നിന്ന് ചെറുതിലേക്ക് sort ചെയ്യുന്നു.

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.sort() list-നെ തന്നെ മാറ്റുന്നു.

Challenge

+30 XP

students = [("Arun", 80), ("Priya", 95), ("Kavi", 70), ("Ravi", 88)]. ഏറ്റവും കൂടുതൽ marks ആദ്യം വരുന്ന രീതിയിൽ sort ചെയ്ത് പേരുകൾ മാത്രം, ഓരോ വരിയിലും ഒന്ന്, print ചെയ്യൂ.

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