def _median(collection):
    """ Calculates the median of an collection, eg a list. """
    ordered = sorted(collection)
    len_ = len(collection)
    middle = len_ // 2

    if not ordered:
        return -1
    elif len_ % 2 == 1:
        return ordered[middle]
    else:
        return (ordered[middle - 1] + ordered[middle]) / 2