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.