Re: Replacing Numbers in a List
- To: mathgroup at smc.vnet.net
- Subject: [mg68274] Re: Replacing Numbers in a List
- From: "dkr" <dkrjeg at adelphia.net>
- Date: Mon, 31 Jul 2006 03:45:41 -0400 (EDT)
- References: <eahsgh$op1$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Gregory, In[37]:= x=Range[1,10];y={1,3,5,7,9,11}; In[38]:= Replace[x,_?(MemberQ[y,#]&)->222,{1}] Out[38]= {222,2,222,4,222,6,222,8,222,10} If you want to use ReplacePart, you can get rid of the Do loop by using a more general pattern in Position: In[39]:= ReplacePart[x,222,Position[x,_?(MemberQ[y,#]&),{1},Heads->False]] Out[39]= {222,2,222,4,222,6,222,8,222,10} dkr