
HumanEval Question 47
HumanEval Question 47
Prompt
Complete the following Python function: ```python def median(l: list): """Return median of elements in the list l. >>> median([3, 1, 2, 4, 5]) 3 >>> median([-10, 4, 6, 1000, 10, 20]) 15.0 """ ```
Answer guidance
Canonical solution (function body): l = sorted(l) if len(l) % 2 == 1: return l[len(l) // 2] else: return (l[len(l) // 2 - 1] + l[len(l) // 2]) / 2.0
Drag to resize
Drag to resize
Drag to resize
Drag to resize
Drag to resize