### 20.1.5 Median

Although the average of a list of numbers typically means the mean, there are other notions of “average”. Another such notion is the median; the median of a list of numbers is the middle number when they are listed in numeric order. For example, the median of the list [1,2,5,7,20] is simply 5. If the length of a list of numbers is even, the median is the mean of the two middle numbers; for example, the median of [1,2,5,7,20,21] is (5+7)/2=6.

The median function finds the median of a list.

- median takes one mandatory argument and one optional argument:
  - L, a list of numbers.
  - Optionally, W, a list of positive integers for weights, where the weight of number represents how many times it is counted in a list.
- median(L⟨,W⟩) returns the median of the list.

#### Examples

median([1,2,5,7,20])

5 |  |  |  |  |  |  |  |  |  |

median([1,2,5,7,20],[5,3,2,1,2])

2 |  |  |  |  |  |  |  |  |  |

since the median of 1,1,1,1,1,2,2,2,5,5,7,20,20 is 2.