UNCLASSIFIED

Skip to content
Snippets Groups Projects

python sets and unions

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by James Orman
    Edited
    snippetfile1.txt 233 B
    
    s1 = {'a', 'b', 'c', 'd'}
    s2 = {'x', 'z', 'a', 'a', 'e', 'v'}
    
    print("s1",s1)
    print("s2",s2)
    
    s3 = s1 | s2
    
    s = s2 - s1
    
    intersect = s1.intersection(s2)
    
    print("Union:",s3)
    print("Difference:", s)
    print("Intersection:", intersect)
    
    0% or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment