Sorting is just putting things in order — like alphabetizing names, arranging numbers from smallest to largest, or organizing by height.
🐍 In Python, you can sort a list using the sorted() function.
Let’s say you have a list of words, and you want to sort them by how long each word is, not alphabetically.
That’s where lambda comes in.
Here’s what’s happening:
sorted() normally sorts alphabetically.
The key= part lets us tell Python how to sort.
lambda word: len(word) tells it: “Use the length of the word as the sorting rule.”
Think of lambda as a mini function that you write in one line
Example: lambda word: len(word)
This says: “Hey, take the word and return how long it is.”
✅ Output: ['dog', 'cat', 'elephant', 'hippopotamus']
key=lambda student: student[1]
key=lambda student: student[0]
The sort shown will sort by YEAR