lambda a function without a name;
- anonymous functions
- one line only
- single expression only
- stored in a variable
- When do you use it?
- Pass a function into another function as a parameter
- lambda variables (comma separated): expression
- lambda functions are used with other functions. Usually with map, filter, sort
- Uses
functionto test the truthiness of each value in the sequence and returns a filtered list. functionmust return True or False
filter(function, sequence)- Uses
functionto transform the values in a sequence
map(function, sequence)- Uses
functionto sort values
sorted(sequence, key=function)