Re: List Question
- To: mathgroup at smc.vnet.net
- Subject: [mg67949] Re: List Question
- From: Bill Rowe <readnewsciv at earthlink.net>
- Date: Thu, 13 Jul 2006 06:54:59 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
On 7/12/06 at 5:05 AM, simonjbale at gmail.com (Simon Bale) wrote:
>I have a list with the following structure:
>{{x1,y1},{x2,y2},{x3,y3,z3},{x4,y4}...}
>As you can see some of the data points have three elements. I would
>like to remove these z elements so that the list has a structure
>{{x1,y1},{x2,y2},{x3,y3},{x4,y4}...}. I'm not sure how to achieve
>this so any help is greatly appreciated.
This is easily done with pattern matching as follows:
In[6]:=
data={{x1,y1},{x2,y2},{x3,y3,z3},{x4,y4}};
In[7]:=
data/.{a_,b_,_}->{a,b}
Out[7]=
{{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}}
--
To reply via email subtract one hundred and four