MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: ReplaceAll applied to List


Hannes Kessler wrote:
> Hello,
> 
> I want to apply transformation rules to those elements of a list which
> are not lists themselves. The structure of the list is unknown in
> advance.
> 
> The following simple examples illustrate my my problems with ReplaceAll
> and List:
> 
> Expected result:
> {1., {2}, 3} /. x_?NumericQ :> g
> --> {g,{g},g}

<snip>

You could use the built-in function *Replace* [1] with its third 
argument set to one (that is only the first level of the list will be 
analyzed):

"Replace[expr, rules, levelspec] applies rules to parts of expr 
specified by levelspec."

For instance,

In[1]:=
Replace[{1., {2}, 3}, (x_)?NumericQ :> g, 1]

Out[1]=
{g, {2}, g}

Regards,
Jean-Marc

1. http://documents.wolfram.com/mathematica/functions/Replace


  • Prev by Date: Re: simplifying inequalities
  • Next by Date: Re: RealTime3D
  • Previous by thread: Re: ReplaceAll applied to List
  • Next by thread: ReplaceAll applied to List