forked from chhayac/pyfun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymmetric_difference.py
36 lines (30 loc) · 1.01 KB
/
symmetric_difference.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Task
# 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 M or N but do not exist in both.
#
# Input Format
# The first line of input contains an integer, M.
# The second line contains M space-separated integers.
# The third line contains an integer, N.
# The fourth line contains N space-separated integers.
#
# Output Format
# Output the symmetric difference integers in ascending order, one per line.
# Sample Input
# 4
# 2 4 5 9
# 4
# 2 4 11 12
# Sample Output
# 5
# 9
# 11
# 12
# ^ symbol can also be used to compute the symmetric difference of two sets.
if __name__ == '__main__':
# take input from stdin
M = input();m = input().split()
N = input();n = input().split()
# compute the symmetric difference of 2 sets & create a list, then sort the list converting
# each element of list to integer & joining with newline
print("\n".join(sorted(list(set(m) ^ set(n)), key = int)))