Re: Mapping tag-value lists to a third
- To: mathgroup at smc.vnet.net
 - Subject: [mg132447] Re: Mapping tag-value lists to a third
 - From: Bill Rowe <readnews at sbcglobal.net>
 - Date: Tue, 18 Mar 2014 01:28:44 -0400 (EDT)
 - Delivered-to: l-mathgroup@mail-archive0.wolfram.com
 - Delivered-to: l-mathgroup@wolfram.com
 - Delivered-to: mathgroup-outx@smc.vnet.net
 - Delivered-to: mathgroup-newsendx@smc.vnet.net
 
On 3/17/14 at 2:27 AM, carlos.felippa%colorado.edu at gtempaccount.com
wrote:
>I have 2 lists of equal length such as
>tag={0, 1, 0, 0, 0, 1, 0, 1};  val={f1,f2,f3,f4,f5,f6,f7,f8}
>and want to produce a third:
>tagval={f2,f6,f8}
Pick does this, i.e.
In[1]:= tag = {0, 1, 0, 0, 0, 1, 0, 1}; val = {f1, f2, f3, f4,
f5, f6,
    f7, f8};
In[2]:= tagval = Pick[val, tag, 1]
Out[2]= {f2,f6,f8}
Or could use Cases as follows:
In[3]:= Cases[Transpose[{tag, val}], {1, _}][[All, -1]]
Out[3]= {f2,f6,f8}
Not sure how timing will be for either of these with really long lists