MathGroup Archive 2009

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

Search the Archive

Re: complicated list selector

  • To: mathgroup at smc.vnet.net
  • Subject: [mg98480] Re: complicated list selector
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Fri, 10 Apr 2009 04:58:07 -0400 (EDT)

On 4/9/09 at 5:55 AM, summertan at hotmail.com (summer) wrote:

>I have the following list

>data = {  {11, {121, 122}},   {21, {221, 222}},  {31, {321, 322}} };

>From each sublist, I want to extract the first element and the second
>element of the second sub-sub-list that is:

>wanted_result={  {11, 122},   {21, 222},   {31, 322}   }

>I tried

>data[[All, {1, {2,1}}]]

>but it gives me error.

>What is the right selector ?

Here are three ways to achieve your desired result

In[3]:= data[[All, 2]]

Out[3]= {{121, 122}, {221, 222}, {321, 322}}

In[4]:= Last /@ data

Out[4]= {{121, 122}, {221, 222}, {321, 322}}

In[5]:= data /. {a_, b_} -> b

Out[5]= {{121, 122}, {221, 222}, {321, 322}}



  • Prev by Date: Re: complicated list selector
  • Next by Date: Re: complicated list selector
  • Previous by thread: Re: complicated list selector
  • Next by thread: Re: complicated list selector