1

Given two lists

a = [1,2,3,4,5]
b = [2,4,6,7]

output similar element

c = [2,4]

Is there API to compare and extract similar elements from two lists? It could be possible to do it by compare element by element, but I am wondering if there are already API.

Hrqls
  • 2,944
  • 4
  • 34
  • 54
twfx
  • 1,664
  • 9
  • 29
  • 56

1 Answers1

2
print set(a).intersection(set(b))

use intersection to get common elements in the both list

sundar nataraj
  • 8,524
  • 2
  • 34
  • 46