Lambda Functions
A lambda is a tiny function with no def name block.
It is a one-line recipe written inline.
Think of a sticky note instead of a full recipe card.
Good for short jobs. Use def when the steps get longer.
Lambda shape
Write lambda, then parameters, then a colon, then one expression.
The expression is the return value.
Same idea with def
These two do the same job.
def is clearer when you will reuse the function a lot.
With map
map applies a function to each item in a list.
A lambda fits well for a tiny transform.
With filter
filter keeps items where the function returns True.
With sorted key
sorted can take a key function.
The key decides how to compare items.
When not to use lambda
When you need many lines
When you need clear documentation
When the same function appears in many places
When a name would help the reader
Tip: Use lambda for tiny one-line transforms. Use def for real recipes.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.