<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def resample(sig, old=1, new=1, order=3, zero=0.):
 """ Generic resampler based on Waring-Lagrange interpolators. Parameters sig : Input signal (any iterable). old : Time duration reference (defaults to 1, allowing percentages to the ``new`` keyword argument). This can be float number, or perhaps a Stream instance. new : Time duration that the reference will have after resampling. For example, if ``old = 1, new = 2``, then there will be 2 samples yielded for each sample from input. This can be a float number, or perhaps a Stream instance. order : Lagrange interpolator order. The amount of neighboring samples to be used by the interpolator is ``order + 1``. zero : The input should be thought as zero-padded from the left with this value. Returns ------- The first value will be the first sample from ``sig``, and then the interpolator will find the next samples towards the end of the ``sig``. The actual sampling interval (or time step) for this interpolator obeys to the ``old / new`` relationship. Hint ---- The time step can also be time-varying, although that's certainly difficult to synchonize (one sample is needed for each output sample). Perhaps the best approach for this case would be a ControlStream keeping the desired value at any time. Note ---- The input isn't zero-padded at right. It means that the last output will be one with interpolated with known data. For endless inputs that's ok, this makes no difference, but for finite inputs that may be undesirable. """

  sig = Stream(sig)
  threshold = .5 * (order + 1)
  step = old / new
  data = deque([zero] * (order + 1), maxlen=order + 1)
  data.extend(sig.take(rint(threshold)))
  idx = int(threshold)
  isig = iter(sig)
  if isinstance(step, Iterable):
    step = iter(step)
    while True:
      yield lagrange(enumerate(data))(idx)
      idx += next(step)
      while idx > threshold:
        data.append(next(isig))
        idx -= 1
  else:
    while True:
      yield lagrange(enumerate(data))(idx)
      idx += step
      while idx > threshold:
        data.append(next(isig))
        idx -= 1