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.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Python
  3. Sets
  4. Symmetric Difference
  5. Discussions

Symmetric Difference

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 834 Discussions, By:

votes

Please Login in order to post a comment

  • NamrataR
    5 years ago+ 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)))
    
    177|
    Permalink
    View more Comments..
  • newmocart
    6 years ago+ 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))
    
    127|
    Permalink
    View more Comments..
  • murad_
    3 years ago+ 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])
    
    26|
    Permalink
    View more Comments..
  • bhumilsarvaiya
    5 years ago+ 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')
    
    23|
    Permalink
  • bageYARU
    4 years ago+ 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)
    
    17|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature