Behaviour of Replace
- To: mathgroup at smc.vnet.net
- Subject: [mg114852] Behaviour of Replace
- From: Peter Breitfeld <phbrf at t-online.de>
- Date: Mon, 20 Dec 2010 00:40:28 -0500 (EST)
Suppose I have this nested list: demo = {1, {2, {3, {4, {5, {6, {7, {8, 8}}}}}}}} Replace[demo, {x_, y_} :> {x, a, y}, -1] Out={1, {2, a, {3, a, {4, a, {5, a, {6, a, {7, a, {8, a, 8}}}}}}}} I expected to have an a after the 1 too, what I tried to get using Replace[demo,{x_,y_}:>{x,a,y},-1,Heads->True] but this gives the same result as above. But this will do what I wanted: Replace[demo, {x_, y_} :> {x, a, y}, {0, 8}] Out={1, a, {2, a, {3, a, {4, a, {5, a, {6, a, {7, a, {8, a, 8}}}}}}}} Can somone please explain this behaviour? What I found was that Level[demo,{0}] returns {{1},{2,{3...} beeing {demo} Thank you -- _________________________________________________________________ Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de
- Follow-Ups:
- Re: Behaviour of Replace
- From: Andrzej Kozlowski <akoz@mimuw.edu.pl>
- Re: Behaviour of Replace