An estate agent reports the typical sale price on a street as the price in the middle: once the prices are put in order, half of the sales are at or below it and half at or above. With an odd number of sales that is the single middle price; with an even number it is the mean of the two middle prices.
Write middle_price(prices) that returns this middle price. The list prices is in the order the houses were sold and must not be changed by your function.
Examples
Input: prices = [240, 1850, 199, 310, 265]
Output: 265
Explanation: in order the prices are 199, 240, 265, 310, 1850; the third one is in the middle.
Input: prices = [300, 180, 220, 410]
Output: 260.0
Explanation: in order 180, 220, 300, 410; the middle pair is 220 and 300, and (220 + 300) / 2 = 260.0.
Constraints
1 <= len(prices) <= 10**5- every price is a whole number (thousands of pounds) with
1 <= price <= 10**6 - a whole-number answer may be returned as an
intor afloat
Goals
- Find the middle of the data once it is in order
- Handle an even number of values by averaging the middle pair
- Leave the caller's list unchanged