Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

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}}


  • Prev by Date: Evaluate to...
  • Next by Date: diagonal Ramsey number R(n,n)= 4k+2, R(5,5)=46
  • Previous by thread: Re: Select list elements and exchange them
  • Next by thread: combining ArrayPlot with ListLinePlot