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.