We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Sets
- Symmetric Difference
- Discussions
Symmetric Difference
Symmetric Difference
Sort by
recency
|
1177 Discussions
|
Please Login in order to post a comment
M = int(input()) m_store = set(map(int,input().split()))
N = int(input()) n_store = set(map(int,input().split()))
z = m_store.symmetric_difference(n_store)
store = sorted(z) for i in store: print(i)
This is the most efficient basic solution.
M_size, M_set = input(), set(map(int, input().split(' ')))
N_size, N_set = input(), set(map(int, input().split(' ')))
S = sorted(list(M_set.symmetric_difference(N_set)))
[print(i) for i in S]
Using list comprehension in the end will increase performance
![](
M = int(input()) Mm = list(map(int, input().split()))
N = int(input()) Nn = list(map(int, input().split()))
diff_1 = set(Mm).difference(Nn) diff_2 = set(Nn).difference(Mm)
final_set =sorted(list(diff_2.union(diff_1)))
for i in range(len(final_set)): print(final_set[i])
![](
M = int(input()) Mm = list(map(int, input().split()))
N = int(input()) Nn = list(map(int, input().split()))
diff_1 = set(Mm).difference(Nn) diff_2 = set(Nn).difference(Mm)
final_set =sorted(list(diff_2.union(diff_1)))
for i in range(len(final_set)): print(final_set[i])