Re: Something very simple.....

• To: mathgroup at smc.vnet.net
• Subject: [mg87124] Re: Something very simple.....
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Tue, 1 Apr 2008 05:41:31 -0500 (EST)
• Organization: The Open University, Milton Keynes, UK
• References: <fssr6s\$biu\$1@smc.vnet.net>

```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.....