def median(values: 'List[Union[int, float]]', inplace: 'bool'=False):
    """ TODO Use doctest here.
  >>> print(median([1, 2, 3]))
  2
  >>> print(median([1, 2]))
  1.5
  """
    assert isinstance(values, list)
    n = len(values)
    assert n > 0
    if n == 1:
        return values[0]
    if inplace:
        values.sort()
    else:
        values = list(sorted(values))
    return values[n >> 1] if n >> 1 << 1 != n else (values[(n >> 1) - 1] +
        values[n >> 1]) / 2.0
