Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1995

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

Search the Archive

Re: Re: interchanging elements in a list

  • To: mathgroup at
  • Subject: [mg2049] Re: [mg2005] Re: [mg1993] interchanging elements in a list
  • From: Allan Hayes <hay at>
  • Date: Sat, 16 Sep 1995 01:43:38 -0400

Richard Mercer <richard at>
in [mg2005] Re: [mg1993] interchanging elements in a list
gives four ways of interchanging elements (see code below - I  add  
indices to distinguish the four functions).


Interchange1 and Interchange4 are fine but the other two replace by  
value and can give incorrect results:

Interchange2[ {1,1,2},2,3]
	{2, 2, 1}

Interchange3[ {1,1,2},2,3]
	{2, 2, 1}

Allan Hayes
hay at


   list /. {list[[m]]->list[[n]],list[[n]]->list[[m]]};

   list /. {#1->#2,#2->#1}& @@ Part[list,{m,n}];

   Part[list,Range[1,Length[list]] /. {m->n,n->m}];

  • Prev by Date: Re: ContourPlots
  • Next by Date: Mathematica and Netscape
  • Previous by thread: Re: interchanging elements in a list
  • Next by thread: Lemke-Algorithm in Mathematica-Code