MathGroup Archive 2008

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg94073] Re: [mg94042] Re: easier method for Flatten[Position[list2,x_x...??
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Thu, 4 Dec 2008 07:14:39 -0500 (EST)
  • Reply-to: hanlonr at cox.net

To see the long form for any short form use FullForm

a -> b // FullForm

Rule[a,b]

a == b // FullForm

Equal[a,b]

a > b // FullForm

Greater[a,b]


Bob Hanlon

---- Curtis Osterhoudt <cfo 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
See http://www.gnu.org/philosophy/no-word-attachments.html
==========================
==========================
========


--

Bob Hanlon



  • Prev by Date: How to substitute a function?
  • Next by Date: Re: Calculating with Units
  • Previous by thread: Re: easier method for Flatten[Position[list2,x_x...??
  • Next by thread: Re: DeleteCases and multiple patterns