def reversals(series, left=False, right=False):
series = iter(series)<EOL>x_last, x = next(series), next(series)<EOL>d_last = (x - x_last)<EOL>if left:<EOL><INDENT>yield x_last<EOL><DEDENT>for x_next in series:<EOL><INDENT>if x_next == x:<EOL><INDENT>continue<EOL><DEDENT>d_next = x_next - x<EOL>if d_last * d_next < <NUM_LIT:0>:<EOL><INDENT>yield x<EOL><DEDENT>x_last, x = x, x_next<EOL>d_last = d_next<EOL><DEDENT>if right:<EOL><INDENT>yield x_next<EOL><DEDENT>
Iterate reversal points in the series.

    A reversal point is a point in the series at which the first derivative
    changes sign. Reversal is undefined at the first (last) point because the
    derivative before (after) this point is undefined. The first and the last
    points may be treated as reversals by setting the optional parameters
    `left` and `right` to True.

    Parameters
    ----------
    series : iterable sequence of numbers
    left: bool, optional
        If True, yield the first point in the series (treat it as a reversal).
    right: bool, optional
        If True, yield the last point in the series (treat it as a reversal).

    Yields
    ------
    float
        Reversal points.