Re: List element manipulation

• To: mathgroup at smc.vnet.net
• Subject: [mg25521] Re: [mg25408] List element manipulation
• From: dkeith at sarif.com
• Date: Thu, 5 Oct 2000 23:50:41 -0400 (EDT)
• References: <gbUB5.94606\$Zh6.213680@ralph.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Here's still another way:

In[8]:=
decrement[lst_] := MapAt[# - 1 &, lst, Length[lst]]

In[9]:=
decrement[{a, b, c}]

Out[9]=
{a, b, -1 + c}

Isn't Mathematica neat?!

Best,

David

In article <gbUB5.94606\$Zh6.213680 at ralph.vnet.net>,
Tomas Garza <tgarza01 at prodigy.net.mx> wrote:
>
> In[1]:=
> {Drop[Range[116, 166, 8], -1], Last[Range[116, 166, 8]] - 1} //
Flatten
> Out[1]=
> {116, 124, 132, 140, 148, 156, 163}
>
> Tomas Garza
> Mexico City
>
> "Martin Rommel" <Martin_Rommel at mac.com> wrote:
>
> > I want to decrement the last number in list. This ought to be easy,
> but my
> > initial attempts did not bear fruits:
> >
> > In[40]:=
> > MapAt[Decrement, Range[116, 166, 8], -1]
> >
> >     Decrement::"rvalue": "164 is not a variable with a value, so
its
> value
> > cannot be changed."
> >
> > Out[40]=
> > {116, 124, 132, 140, 148, 156, 164--}
> >
> > Do I need to use ReplacePart? That works but still gives me an
error!
> >
> > In[53]:=
> > Range[116, 166, 8] // ReplacePart[#, --Last[#], -1] &
> >
> >     Set::"write": "Tag Last in Last[{116, 124, 132, 140, 148, 156,
> 164}] is
> > Protected."
> >
> > Out[53]=
> > {116, 124, 132, 140, 148, 156, 163}
> >
> > Different error here:
> >
> > In[51]:=
> > Range[116, 166, 8] // ReplacePart[#, --#[[-1]], -1] &
> >
> >     Set::"setps": "{116, 124, 132, 140, 148, 156, 164} in
assignment
> of part
> > is not a symbol."
> >
> > Out[51]=
> > {116, 124, 132, 140, 148, 156, 163}
> >
> >
> > Anybody out there able to enlighten me?
>
>

Sent via Deja.com http://www.deja.com/