This question already has an answer here:

Splicing a list of arguments into a function with Sequence

2 answers

I want to get the intersection of all sublists of list in an easy way.

list = {{a,b,c},{d,e,a},{c,a,f}]}

Intersection[list[[1]],list[[2]],list[[3]]]

Intersection[list]

The first Intersection command works well (it gives {a}). But the second one does not work. I understand that there’s a syntax error (list is a list of lists, but Intersection only takes individual lists. However, there must be a simple way around it? In my case, list has more than 3 sublists which makes it hard to write them all down.

Thanks

=================

=================

2 Answers

2

=================

As pointed out by Sjoerd C de Vries and andre an easy way is to replace the head of your list with Intersection by using Apply (i.e, @@)

Intersection @@ list

(* {a} *)

4

IMHO Intersection @@ list would be easier.

– Sjoerd C. de Vries

Oct 9 ’15 at 22:33

@SjoerdC.deVries IMO you are 100% correct 🙂 Answer edited accordingly.

– Jack LaVigne

Oct 11 ’15 at 13:42

As I said in the comments :

Apply[Intersection, list] (or Intersection @@ list)