MathGroup Archive 2006

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

Search the Archive

Re: ReplaceAll applied to List

  • To: mathgroup at
  • Subject: [mg72335] Re: ReplaceAll applied to List
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at>
  • Date: Tue, 26 Dec 2006 06:38:49 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <em8jdu$pel$>

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}


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 

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

For instance,

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

{g, {2}, g}



  • 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