- Programming structures designed to manipulate lists
- Preferred method is to use list comprehensions
Create a list by applying a function to each element in an existing list.
map(<function>, list)
Create a list by filtering out elements of an existing list.
- Anonymous function creation in python
- Similar to
lambda
in racket andfunction
in javascript
Syntax
lambda arguments : expression
- Expression must return a value;
return
is not used
lambda x : 2*x
lambda a, b : a if a > b else b
Compute a single value based on a list.
reduce( function, list )
- The function argument must take 2 parameters
- They represent the previously computed value and the next element in the list
reduce( lambda a, b: a + b, [49, 37, 163, 2])
reduce( lambda a, b: a if a > b else b, [49, 37, 163, 2])