code: def reversals(series, left=False, right=False):
      
      series = iter(series)
  
      x_last, x = next(series), next(series)
      d_last = (x - x_last)
  
      if left:
          yield x_last
      for x_next in series:
          if x_next == x:
              continue
          d_next = x_next - x
          if d_last * d_next < 0:
              yield x
          x_last, x = x, x_next
          d_last = d_next
      if right:
          yield x_next
docs: 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.