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
    • 100+ Java Programs
    • 100+ C Programs
  • 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 .symmetric_difference() operation solution in python

YASH PAL, 31 July 2024

Students of District College have subscriptions to English and French newspapers. Some students have subscribed to English only, some have subscribed to French only, 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 one set has subscribed to the French newspaper. Your task is to find the total number of students who have subscribed to either the English or the French newspaper but not both.

HackerRank Set .symmetric_difference() operation solution in python

Problem solution in Python 2 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT
raw_input()
e = set(raw_input().split())
raw_input()
f = set(raw_input().split())
print len(e^f)

Problem solution in Python 3 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT
_, a = input(), set(input().split())
_, b = input(), set(input().split())
print(len(a.symmetric_difference(b)))

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.symmetric_difference(t))

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.symmetric_difference(s2)
print(len(s1s2))

coding problems python

Post navigation

Previous post
Next post
  • HackerRank Separate the Numbers solution
  • 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
©2025 Programming101 | WordPress Theme by SuperbThemes