def median(items):
    """If `items` has an even length, returns the average of the two
    middle elements. If `items` has an odd length, returns the single
    middle element. If `items` is empty, returns ``None``.
    """
    n = len(items)
    if not n:
        return None
    mid = n // 2
    items = sorted(items)
    if n % 2 == 0:
        return (items[mid - 1] + items[mid]) / 2
    return float(items[mid])