Re: easier method for Flatten[Position[list2,x_x...??
- To: mathgroup at smc.vnet.net
- Subject: [mg94036] Re: easier method for Flatten[Position[list2,x_x...??
- From: Szabolcs Horvát <szhorvat at gmail.com>
- Date: Tue, 2 Dec 2008 05:20:46 -0500 (EST)
- Organization: University of Bergen
- References: <gh0jlg$5mu$1@smc.vnet.net> <gh2h4c$i9k$1@smc.vnet.net>
Szabolcs Horvát 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} > And consider using Dispatch if list2 is used many times, without change.