Re: easier method for Flatten[Position[list2,x_x...??
- To: mathgroup at smc.vnet.net
- Subject: [mg94080] Re: easier method for Flatten[Position[list2,x_x...??
- From: Raffy <raffy at mac.com>
- Date: Thu, 4 Dec 2008 07:15:55 -0500 (EST)
- References: <gh0jlg$5mu$1@smc.vnet.net> <200812020540.AAA19072@smc.vnet.net>
On Dec 3, 2:42 am, Curtis Osterhoudt <c... at lanl.gov> wrote: > 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 > Seehttp://www.gnu.org/philosophy/no-word-attachments.html > ========================= == > ========================= == > ======== a->b//FullForm
- References:
- Re: easier method for Flatten[Position[list2,x_x...??
- From: Szabolcs Horvát <szhorvat@gmail.com>
- Re: easier method for Flatten[Position[list2,x_x...??