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 मोठ्या ते लहान लावते.

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.