Python Set Intersection Operation

Author: Al-mamun Sarkar Date: 2020-03-24 17:50:17

Python Set Intersection Operation. The following code shows how to perform Intersection operation on set in python. This is the solution of the HackerRank Set .intersection() Operation Python Sets problem.

Solution Code:

n = int(input())
english = set( map( int, input().split() ) )

p = int(input())
franch = set( map( int, input().split() ) )
new_set = english.intersection(franch)
print( len(new_set) )

 

Test Input:

9
1 2 3 4 5 6 7 8 9
9
10 1 2 3 11 21 55 6 8

Test Output:

5