Re: Handling a list: Could you find a more elegant solution?
- To: mathgroup at smc.vnet.net
- Subject: [mg38278] Re: [mg38195] Handling a list: Could you find a more elegant solution?
- From: Tomas Garza <tgarza01 at prodigy.net.mx>
- Date: Tue, 10 Dec 2002 04:17:32 -0500 (EST)
- References: <200212050829.DAA03909@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Elegance often lies in the eye of the beholder. But this is shorter than the
one you propose, I guess:
In[1]:=
Rest[list1 + RotateRight[list1]]/2
Out[1]=
{(a + b)/2, (b + c)/2, (c + d)/2, (d + e)/2}
Tomas Garza
Mexico City
----- Original Message -----
From: <guillerm at usal.es>
To: mathgroup at smc.vnet.net
Subject: [mg38278] [mg38195] Handling a list: Could you find a more elegant solution?
> I have a list:
>
> list1 = {a, b, c, d, e};
>
> I want manipulate the list to obtain:
>
> (*Out[]:{(a + b)/2, (b + c)/2, (c + d)/2, (d + e)/2}*)
>
> It can be done for this function
>
> f[data_List] := Drop[Plus @@ NestList[RotateRight, data,
> 1], 1]/2
>
> f[list1]
>
> but I am sure that some member of the group can find a more elegant
function. I
> will appreciate to know it.
>
> Thanks
>
> Guillermo Sanchez
>
>
> ---------------------------------------------
> This message was sent using Endymion MailMan.
> http://www.endymion.com/products/mailman/
>
>
>
- References:
- Handling a list: Could you find a more elegant solution?
- From: guillerm@usal.es
- Handling a list: Could you find a more elegant solution?