MathGroup Archive 2008

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

Search the Archive

Re: Something very simple.....


Steve Gray wrote:

<snip>

> 2. I have two lists, lsta={a,b,c,d,e,f} and lstb={1,3,4}.
> I want the elements of lsta that do NOT correspond to elements
> of lstb, in this case everything from lsta except elements
> 1,3, and 4: result={b,e,f}. 
> (lstb won't have entries larger than Length[lsta]).

The following will do it:


     Pick[lsta,
      If[MemberQ[lstb, #], False, True] & /@ Range@Length@lsta]


Here is how it works:

lsta = {a, b, c, d, e, f} ; lstb = {1, 3, 4};

(* We build a list of same length as lsta since Pick expects two list of 
same length. *)

Range@Length@lsta

{1, 2, 3, 4, 5, 6}

(* We mark what elements must be taken. *)

If[MemberQ[lstb, #], False, True] & /@ Range@Length@lsta

{False, True, False, False, True, True}

(* The final expression is *)

Pick[lsta,
  If[MemberQ[lstb, #], False, True] & /@ Range@Length@lsta]

{b, e, f}


Regards,
-- Jean-Marc


  • Prev by Date: Re: Problem with FourierParameters
  • Next by Date: Re: How to put text on a curved surface?
  • Previous by thread: Re: Something very simple.....
  • Next by thread: Re: Something very simple.....