def _maybe_list_replace(lst, sublist, replacement):
  """Replace first occurrence of sublist in lst with replacement."""
  new_list = []
  idx = 0
  replaced = False
  while idx < len(lst):
    if not replaced and lst[idx:idx + len(sublist)] == sublist:
      new_list.append(replacement)
      replaced = True
      idx += len(sublist)
    else:
      new_list.append(lst[idx])
      idx += 1
  if not replaced:
    return None
  return new_list