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 1993

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

Search the Archive

re: Lists

  • To: mathgroup at
  • Subject: re: Lists
  • From: tgayley (Todd Gayley)
  • Date: Fri, 29 Jan 1993 11:09:34 -0600

Neil (neilb at asks:

>Hi, I am try to add one to the last element of a list.


>>In[5]:= l={x,z,y,0,0}
>>Out[5]= {x, z, y, 0, 0}
>>In[6]:=  l/.l[[Length[l] ]]->l[[Length[l] ]]+1
>>Out[6]= {x, z, y, 1, 1}
>which is curious. Does anybody know why
>this doesn't produce

The substitution 

     l/.l[[Length[l] ]]->l[[Length[l] ]]+1

evaluates to

     l /. 0->1

which explains your results. To modify a list in this way, you need to use

     ReplacePart[l, Last[l]+1, Length[l]]

Todd Gayley
WRI Technical Support

  • Prev by Date: Re: Lists
  • Next by Date: Mathematica Help
  • Previous by thread: Re: Lists
  • Next by thread: Re: Lists