MathGroup Archive 1997

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

Search the Archive

Re: selecting from lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg6134] Re: [mg6120] selecting from lists
  • From: Lou Talman <me at talmanl.mscd.edu>
  • Date: Sun, 23 Feb 1997 00:10:47 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

Murray Eisenberg wrote:

> The problem: given an arbitrary list v and a list b of the same
> length, whose entries are all Boolean (True or False), construct a
> function s[v, b] whose result is a list consisting only of those
> entries of v for which the corresponding entries in b are True.  For
> example,
> 
>    v = {3, 82, 7, -12, 5};
>    b = {False, True, True, False};
>    s[v, b]
> {82, 7}


How about

     s[v_, b_] := Cases[Transpose[{v, b}], {x_, True} -> x]
     
--Lou Talman



  • Prev by Date: Stereo Sound
  • Next by Date: Re: selecting from lists
  • Previous by thread: Stereo Sound
  • Next by thread: Re: selecting from lists