One more func - with unlimited list depth.
;; list - list of positions from top to sub, 0 idx as first '(0 1 1) to get '((0 (0 "target"))) - new item
(defun lth-rep (lst lev new)
(mapcar '(lambda (itm) (if (= (car lev) (vl-position itm lst))
(if (and (cdr lev) (listp itm))
(lth-rep itm (cdr lev) new)
new)
itm))
lst))
Example for your case: (lth-rep A '(7 2) "new")
Or if you prefer 1 based indexing:
;; list - list of positions from top to sub, 1 idx as first '(1 2 2) to get '((0 (0 "target"))) - new item
(defun lth-rep1 (lst lev new)
(mapcar '(lambda (itm) (if (= (car lev) (1+ (vl-position itm lst)))
(if (and (cdr lev) (listp itm))
(lth-rep1 itm (cdr lev) new)
new)
itm))
lst))
(lth-rep1 A '(8 3) "new")