MathGroup Archive 2008

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

Search the Archive

Re: easier method for Flatten[Position[list2,x_x...??

  • To: mathgroup at smc.vnet.net
  • Subject: [mg94042] Re: easier method for Flatten[Position[list2,x_x...??
  • From: Curtis Osterhoudt <cfo at lanl.gov>
  • Date: Wed, 3 Dec 2008 05:42:19 -0500 (EST)
  • Organization: LANL
  • References: <gh0jlg$5mu$1@smc.vnet.net> <200812020540.AAA19072@smc.vnet.net>
  • Reply-to: cfo at lanl.gov

  These methods based on the replacement list are very clever! I have long 
gotten used to the replacements notation, but didn't know it could be used 
like this.
   I tried to see if there was any documentation provided with Mathematica 
(v. 7, here) illustrating anything like that. However, the only documentation I can find on Rule gives the shorthand right-arrow notation "->" and say
s NOTHING about the Rule[lhs, rhs] possibility (I had to deduce that from the solutions posted here, and look at the FullForm of some replacements). Can anyone point me to a spot in the documentation where an example using the "Rule[lhs, rhs]" notation is used or explained? If not, it would be a nice improvement in future versions.

          Regards,
                       C.O.

On Monday 01 December 2008 22:40:27 Szabolcs Horv=C3=A1t wrote:
> Van Der Burgt, Maarten wrote:
> > Dear all,
> >
> > Below I have two lists.
> >
> > The elements x in list1 all appear again in the 2nd level of list2
> > together with an associated parameter xP.
> >
> > I want to extract the xP as illustrated below.
> >
> > I have the feeling it can be done in an easier way.
> >
> >
> >
> > Does anyone have an idea how?
>
> Like this:
>
> In[1]:=
> list1 = {a, b, b, e};
> list2 = {{a, aP}, {b, bP}, {c, cP}, {d, dP}, {e, eP}, {f, fP}};
>
> In[3]:= list1 /. Rule @@@ list2
> Out[3]= {aP, bP, bP, eP}
>
>
>
> >
> >
> >
> > Thanks for your help,
> >
> >
> >
> > Maarten
> >
> >
> >
> >
> >
> > list1={a,b,b,e};
> >
> > list2={{a,aP},{b,bP},{c,cP},{d,dP},{e,eP},{f,fP}};
> >
> >
> >
> >
> >
> > pos = Flatten[Position[list2,x_List/;x[[1]]==#]&/@list1];
> >
> >
> >
> > list2[[pos,2]]
> >
> >
> >
> > Out-> {aP,bP,bP,eP}
> >
> >
>
>



=2D-
==========================
==========================
========
Curtis Osterhoudt
cfo at remove_this.lanl.and_this.gov
PGP Key ID: 0x4DCA2A10
Please avoid sending me Word or PowerPoint attachments
See http://www.gnu.org/philosophy/no-word-attachments.html
==========================
==========================
========


  • Prev by Date: Re: Formating ::usage strings
  • Next by Date: Re: InstallJava::fail
  • Previous by thread: Re: easier method for Flatten[Position[list2,x_x...??
  • Next by thread: RE: Re: easier method for Flatten[Position[list2,x_x...??