Categories
Computer Science

Solving Problem: Symmetric Difference

(Sets)

Given 2 sets of integers M and N, print their symmetric difference in ascending order. The term symmetric difference indicates those values that exist in either but do not exist in both.

Python
# Enter your code here. Read input from STDIN. Print output to STDOUT
M = int(input())
li_M = list(map(int, input().split()))
N = int(input())
li_N = list(map(int, input().split()))
sM = set(li_M)
sN = set(li_N)
sD = sM.symmetric_difference(sN)
sorted_S = sorted(sD)
for i in sorted_S:
print(i)

https://www.hackerrank.com/challenges/symmetric-difference/problem

Priyanka B.'s avatar

By Priyanka B.

Hello and welcome to my little corner of internet!! I am a techie. I am very interested to discover and innovate new advances in science and technology. Blogging is one of my hobbies which I think is very useful for broadening my knowledge horizons and help me grow my skills. Apart from blogging I have also little taste in artistic skills and literature, which can keep my writing and posts tangy.

Whether you stumbled in by chance or came here on purpose, I hope you find something that sparks your curiosity or makes you think a little deeper. Thanks for stopping by!!

Leave a comment