Setting the value of a list item

I want to set the value of an item in a list. The code that does this has to work regardless of the depth to the list.

For instance set the value of r[[1,1,1,....,1,1]] to 9. Lets say the list called $r$ is $t$ dimensions deep.

This doesn't see to work:

Part @@ {r}~Join~Table[1, t] = 9


It gives the following error:

Tag Apply in Part@@{...some numbers...} is Protected.

Is there some way to make it work? I tried a few things with Hold and Release but it didn't work.

• r[[Sequence @@ Table[1, {t}]]] = 9 May 4, 2016 at 15:26
• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! May 4, 2016 at 15:31

1 Answer

r = ReplacePart[r, Table[1, t] -> 9];
r[[1, 1, 1, 1, 1, 1, 1, 1, 1]]

• Thanks, ReplacePart works flawlessly. May 4, 2016 at 16:20