HackerRank Set .union() Operation solution in Python YASH PAL, 31 July 202417 January 2026 HackerRank Set .union() Operation Python Solution.union()The .union() operator returns the union of a set and the set of elements in an iterable.Sometimes, the | operator is used in place of .union() operator, but it operates only on the set of elements in set.Set is immutable to the .union() operation (or | operation).TaskThe students of District College have subscriptions to English and French newspapers. Some students have subscribed only to English, some have subscribed to only 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, and the other set is subscribed to the French newspaper. The same student could be in both sets. Your task is to find the total number of students who have subscribed to at least one newspaper.HackerRank Set .union() 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.union(fre) print len(sol)Set .union() problem solution in Python 3.# Enter your code here. Read input from STDIN. Print output to STDOUT n = int(input()) l = list(input().split()) m = int(input()) k = list(input().split()) s1 = set(l) s2 = set(k) print(len(s1.union(s2)))Problem solution in pypy programming.# Enter your code here. Read input from STDIN. Print output to STDOUT n = input() s = set(map(int, raw_input().split())) m = input() t = set(map(int, raw_input().split())) print len(s.union(t))Problem solution in pypy3 programming.n = int(input()) A = set(map(int, input().split())) m = int(input()) B = set(map(int, input().split())) ans = A.union(B) print(len(ans)) coding problems solutions Hackerrank Problems Solutions Python Solutions HackerRankPython