Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #9569 > unrolled thread
| Started by | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| First post | 2012-04-11 22:25 +0000 |
| Last post | 2012-04-11 22:25 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Intersection problem Bob Hanlon <hanlonr357@gmail.com> - 2012-04-11 22:25 +0000
| From | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| Date | 2012-04-11 22:25 +0000 |
| Subject | Re: Intersection problem |
| Message-ID | <jm50da$2pt$1@smc.vnet.net> |
list1 = {{a, x}, {b, y}, {c, z}};
list2 = {b, c, d};
Select[list1, MemberQ[list2, #[[1]]] &]
{{b, y}, {c, z}}
Cases[list1, _?(MemberQ[list2, #[[1]]] &)]
{{b, y}, {c, z}}
Cases[list1, {x_, _} /; MemberQ[list2, x]]
{{b, y}, {c, z}}
DeleteCases[list1, _?(FreeQ[list2, #[[1]]] &)]
{{b, y}, {c, z}}
DeleteCases[list1, {x_, _} /; FreeQ[list2, x]]
{{b, y}, {c, z}}
Pick[list1, MemberQ[list2, #[[1]]] & /@ list1]
{{b, y}, {c, z}}
Bob Hanlon
On Tue, Apr 10, 2012 at 2:27 AM, Cisco Lane <travlorf@yahoo.com> wrote:
> I need to select out the elements of the first list whose first elements are contained in the second list. For example
>
> first list: {{a,x},{b,y},{c,z}}
>
> second list: {b,c,d}
>
> result: {{b,y},{c,z}}
>
> Is there a quick way to do this? Intersection, maybe somehow?
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web