def ses(path, b):
  """
  Returns an edit script for a given match grid path.
  The edit script transforms sequence A of the match grid
  into sequence B via deletions ("D", index) and inserations
  ("I", A index, B value).
  """

  patch = []
  for i in range(len(path) - 1):
    x, y = path[i]
    nx, ny = path[i + 1]
    dx, dy = nx - x, ny - y
    if dx == 1 and dy == 1:
      pass #match
    elif dx == 1:
      patch.append(("D", x))
    else: #dy == 1:
      patch.append(("I", x, b[y]))

  return patch