Header Ad

HackerRank Set .intersection() operation solution in python

In this hackerrank Set .intersection() operation problem we need to develop a python program that can read an integer input separated with four lines. and then we need to print the output of the total number of students that have subscriptions to both English and French newspapers.

HackerRank Set .intersection() operation solution in python


Problem solution in Python 2 programming.

eng = set()
fre = set()
n = raw_input()
for i in raw_input().split(' '):
  eng.add(i)
m = raw_input()
for i in raw_input().split(' '):
  fre.add(i)
sol = eng.intersection(fre)
print len(sol)


Problem solution in Python 3 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT
num1, st1, num2, st2 = (set(input().split()) for i in range(4))
print(len(st1.intersection(st2)))


Problem solution in pypy programming.

encount = int(raw_input())
enst = set(map(int,raw_input().split(' ')))
frcount = int(raw_input())
frst = set(map(int,raw_input().split(' ')))

studs = enst & frst
print len(studs)


Problem solution in pypy3 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT
n1=input()
li1 = input().split()
s1 = set(li1)
n2=input()
li2 = input().split()
s2 = set(li2)
s1s2 = s1.intersection(s2)
print(len(s1s2))


Post a Comment

0 Comments