1

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

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
keyx
  • 353
  • 1
  • 7

2 Answers2

3

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} *)
Jack LaVigne
  • 14,462
  • 2
  • 25
  • 37
2

As I said in the comments :
Apply[Intersection, list] (or Intersection @@ list)

andre314
  • 18,474
  • 1
  • 36
  • 69