Set Mutations

Sort by

recency

|

818 Discussions

|

  • + 0 comments

    Can we make it even more concise?

    _, A = input(), set(map(int, input().split())) 
    [getattr(A, input().split()[0])(set(map(int, input().split()))) for i in range(int(input()))]
    print(sum(A))
    
  • + 0 comments

    Enter your code here. Read input from STDIN. Print output to STDOUT

    n = input() A = set(map(int, input().split())) num_other_sets = input() for _ in range(int(num_other_sets)): eachset = [input().split()[0], set(map(int, input().split()))] if eachset[0] == "update": A.update(eachset[1]) elif eachset[0] == "intersection_update": A.intersection_update(eachset[1]) elif eachset[0] == "symmetric_difference_update": A.symmetric_difference_update(eachset[1]) elif eachset[0] == "difference_update": A.difference_update(eachset[1])

    print(sum(A))

  • + 0 comments

    set_a_count = int(input()) set_a = set(map(int,input().split())) n = int(input()) for i in range (n): operation = input().split() set_b = set(map(int,input().split())) if operation[0] == "update": set_a.update(set_b) elif operation[0] == "intersection_update": set_a.intersection_update(set_b) elif operation[0] == "difference_update": set_a.difference_update(set_b) else: set_a.symmetric_difference_update(set_b)

    print(sum(set_a))

  • + 0 comments

    m = int(input()) A = input() n = int(input())

    setA = set(map(int, A.split()))

    for i in range(n): line1 = input() B = input()

    words= line1.split()
    op = words[0] 
    np = int(words[1])
    
    list2= B.split()
    setB = set(map(int, list2))
    #setA= setA.op(setB)
    getattr(setA, op)(setB)
    

    sum = 0 for i in setA: sum = sum + i print(sum)

  • + 0 comments
    a=int(input())
    n=set(map(int,input().split()))
    N=int(input())
    for i in range(N):
        c=input().split()
        d=set(map(int,input().split()))
        if(c[0]=='update'):
            n.update(d)
        elif(c[0]=='intersection_update'):
            n.intersection_update(d)
        elif(c[0]=='difference_update'):
            n.difference_update(d)
        else:
            n.symmetric_difference_update(d)
            
    print(sum(n))