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.