HackerRank Set .intersection() operation solution in Python YASH PAL, 31 July 202417 January 2026 HackerRank Set .intersection() operation solution in Python – In this hackerrank Set .intersection() operation problem in python programming, 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..intersection()The .intersection() operator returns the intersection of a set and the set of elements in an iterable.Sometimes, the & operator is used in place of the .intersection() operator, but it only operates on the set of elements in set.The set is immutable to the .intersection() operation (or & operation).>>> s = set("Hacker") >>> print s.intersection("Rank") set(['a', 'k']) >>> print s.intersection(set(['R', 'a', 'n', 'k'])) set(['a', 'k']) >>> print s.intersection(['R', 'a', 'n', 'k']) set(['a', 'k']) >>> print s.intersection(enumerate(['R', 'a', 'n', 'k'])) set([]) >>> print s.intersection({"Rank":1}) set([]) >>> s & set("Rank") set(['a', 'k']) TaskThe students of District College have subscriptions to English and French newspapers. Some students have subscribed only to English, some have subscribed only to French, and some have subscribed to both newspapers.You are given two sets of student roll numbers. One set has subscribed to the English newspaper, one set has subscribed to the French newspaper. Your task is to find the total number of students who have subscribed to both newspapers.HackerRank Set .intersection() operation solution in Python 2.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)Set .intersection() operation problem solution in Python 3.# 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)) coding problems solutions Hackerrank Problems Solutions Python Solutions HackerRankPython