Re: Select list elements and exchange them
- To: mathgroup at smc.vnet.net
- Subject: [mg109861] Re: Select list elements and exchange them
- From: ishii.mitsuo.titanium at nsc.co.jp
- Date: Thu, 20 May 2010 06:38:17 -0400 (EDT)
Hi I received many useful suggestions like these below. Sorry for delayed response. Many thanks Mitsuo (1) pos=Position[testList,{_,{3,4}}] newlist=ReplacePart[testList, pos->{100,{3,5}}] (2) testList /. {_, {3, 4}} -> {100, {3, 4}} (3) ClearAll[sub]; sub[expr_, find_, replace_] := Replace[expr, {_, find} -> {replace, find}, {1}]; (4) sub[{{11, {2, 3}}, {21, {3, 4}}, {34, {5, 6}}, {51, {7, 8}}}, {3, 4}, 100] ==> {{11, {2, 3}}, {100, {3, 4}}, {34, {5, 6}}, {51, {7, 8}}} (5) testList /. {_, {3, 4}} -> {100, {3, 4}} {{11, {2, 3}}, {100, {3, 4}}, {34, {5, 6}}, {51, {7, 8}}} (6) { {11,{2,3}},{21,{3,4}},{34,{5,6}},{51,{7,8}} }/.{x_Integer,{3,4}}->{100,{3,4}}