Re: ReplaceAll applied to List
- To: mathgroup at smc.vnet.net
- Subject: [mg72335] Re: ReplaceAll applied to List
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Tue, 26 Dec 2006 06:38:49 -0500 (EST)
- Organization: The Open University, Milton Keynes, UK
- References: <em8jdu$pel$1@smc.vnet.net>
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