Re: Set in Scan
- To: mathgroup at smc.vnet.net
- Subject: [mg21924] Re: [mg21856] Set in Scan
- From: "Tomas Garza" <tgarza at mail.internet.com.mx>
- Date: Fri, 4 Feb 2000 02:54:51 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Johannes Ludsteck [ludsteck at zew.de] wrote:
> I have to do replacements in very long lists. An efficient way to do
> this is to use
>
> x[[index]]=newElement.
>
> This, however, doesn't work if I want to do replacements for a set of
> lists. If I try to replace the third element in the lists v1, v2
> and v3 by
> typing
>
> Scan[#[[3]] = newElement &, {v1,v2,v3}]
> I get the error message
> Set::setps: #1 in assignment of part is not a symbol.
>
> Any suggestions?
I suggest you use ReplacePart instead of direct assignment:
In[1]:=
g[x_]:= ReplacePart[x,newElement,3]
and then Map this function on the list {v1, v2, v3} thus:
In[2]:=
g[#]&/@{v1,v2,v3}
This works fine.
Tomas Garza
Mexico City