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
+ 28 comments Not a one liner. But easy to understand.
a,b=(int(input()),input().split()) c,d=(int(input()),input().split()) x=set(b) y=set(d) p=y.difference(x) q=x.difference(y) r=p.union(q) print ('\n'.join(sorted(r, key=int)))
+ 18 comments Py2. Shortest what I can
a,b = [set(raw_input().split()) for _ in range(4)][1::2] print '\n'.join(sorted(a^b, key=int))
+ 7 comments This is not the short/best method, but will be easy for beginners to understand. i explained step by step with comments in #
#input M=int(input()) m=input() N=int(input()) n=input() #splitting and mapping(string to int_list) x=list(map(int,m.split())) y=list(map(int,n.split())) #creation of sets a=set(x) b=set(y) #difference in each sets c=a.difference(b) d=b.difference(a) #union of difference e=c.union(d) #converting set to a list result=list(e) #sorting result.sort() #iteration for i in range(len(result)): print(result[i])
+ 2 comments _ , M = input(), set(map(int,input().split())) _ , N = input(), set(map(int,input().split())) print(*sorted(list(M.symmetric_difference(N))),sep='\n')
+ 1 comment ;)
M,m=input(),set(list(map(int,input().split()))) N,n=input(),set(list(map(int,input().split()))) s = sorted(list(m.difference(n))+list(n.difference(m))) for i in s: print (i)
Load more conversations
Sort 834 Discussions, By:
Please Login in order to post a comment