Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

HackerRank Set .union() Operation solution in python

YASH PAL, 31 July 2024

In this Set .union() operation problem we need to develop a python program that can read four lines of input and then we need to print the total number of students who have at least one subscription on the output screen.

HackerRank Set .union() 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.union(fre)
print len(sol)

Problem solution in Python 3 programming.

# 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 python

Post navigation

Previous post
Next post
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
  • Hackerrank Day 14 scope 30 days of code solution
©2025 Programming101 | WordPress Theme by SuperbThemes