Re: Lists to mask other lists
- To: mathgroup at smc.vnet.net
- Subject: [mg19171] Re: [mg19022] Lists to mask other lists
- From: "Wolf, Hartmut" <hwolf at debis.com>
- Date: Tue, 10 Aug 1999 02:52:38 -0400
- Organization: debis Systemhaus
- References: <199908031744.NAA05824@smc.vnet.net.>
- Sender: owner-wri-mathgroup at wolfram.com
Hello Aram,
aram schiffman schrieb:
>
> Howdy.
>
> I am trying to use one list to control the content of a second list.
> (It's not really masking, but...)
>
> Here's what I mean. Let's say
>
> maskList={1,0,0,1,1}
>
> realDealList={aaa,bbb,ccc,ddd,eee}
>
> (* could be filled with anything; same # elements as maskList }
>
> If a 1 appears at position n of maskList, then I leave the corresponding
> element of realDealList alone. But if a 0 appears, then I want to change
> the corresponding element of realDealList in some prescribed way. Let's
> say I change those elements to my first name (aram). Then realDealList
> would become
>
> {aaa,aram,aram,ddd,eee}
>
> I can do this in a loop, which is a really clunky solution, but isn't
> there a way I can Map across my list somehow?
>
> Thanks,
> Aram Schiffman
In[1]:= maskList = {1, 0, 0, 1, 1}
Out[1]= {1, 0, 0, 1, 1}
In[2]:= realDealList = {aaa, bbb, ccc, ddd, eee}
Out[2]= {aaa, bbb, ccc, ddd, eee}
In[3]:= controlList = maskList /. {1 -> False, 0 -> True}
Out[3]= {False, True, True, False, False}
In[4]:= MapThread[If[#2, "aram", #1] &, {realDealList, controlList}]
Out[4]= {aaa, "aram", "aram", ddd, eee}
According to that you might define a function
mapOnlyIf[f_,realDeal_,control_]
kind regards, hw
- References:
- Lists to mask other lists
- From: aram schiffman <aram@sirius.com>
- Lists to mask other lists