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,879
  • 4
  • 32
  • 53
twfx
  • 1,616
  • 9
  • 28
  • 50

1 Answers1

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

use intersection to get common elements in the both list

sundar nataraj
  • 8,200
  • 2
  • 30
  • 44