The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: [mg6134] Re: [mg6120] selecting from lists
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Lou Talman

Posts: 876
Registered: 12/3/04
[mg6134] Re: [mg6120] selecting from lists
Posted: Feb 23, 1997 12:17 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.