def consolidate_grades(grade_decimals, n_expect=None):
    """
    Consolidate several grade_decimals into one.

    Arguments:
        grade_decimals (list): A list of floats between 0 and 1
        n_expect (int): expected number of answers, defaults to length of grade_decimals
    Returns:
        float, either:
            average of grade_decimals padded to length n_extra if
                necessary, and subtracting 1/n_extra for each extra, or
            zero
        whichever is larger.

    Usage:
        >>> consolidate_grades([1, 0, 0.5], 4)
        0.375
        >>> consolidate_grades([1, 0.5, 0], 2)
        0.25
        >>> consolidate_grades([1, 0.5, 0, 0, 0], 2)
        0
    """
    if n_expect is None:
        n_expect = len(grade_decimals)

    n_extra = len(grade_decimals) - n_expect
    if n_extra > 0:
        grade_decimals += [-1] * n_extra
    elif n_extra < 0:
        grade_decimals += [0] * abs(n_extra)

    avg = sum(grade_decimals)/n_expect

    return max(0, avg)