Set Mutations

Sort by

recency

|

855 Discussions

|

  • + 0 comments
    input()
    elm = set(map(int, input().split()))
    N = int(input())
    
    for _ in range(N):
        op, l = input().split()
        getattr(elm, op)(set(map(int, input().split())))
    print(sum(elm))
    
  • + 0 comments

    e = int(input()) e_list = set(list(map(int,input().split()))) op = int(input()) for i in range(0,op): k, num = input().split() if (k == 'intersection_update'): o = set(list(map(int, input().split()))) n = e_list.intersection_update(o) elif (k == 'symmetric_difference_update'): o = set(list(map(int, input().split()))) n = e_list.symmetric_difference_update(o) elif (k == 'difference_update'): o = set(list(map(int, input().split()))) n = e_list.difference_update(o) elif (k == 'update'): o = set(list(map(int, input().split()))) n = e_list.update(o) print(sum(e_list))

  • + 0 comments
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    n = int(input())
    A = set(map(int, input().split()))
    N = int(input())
    for _ in range(N):
        op, l = input().split()
        n_set = set(map(int, input().split()))
        getattr(A, op)(n_set)
    print(sum(A))
    
  • + 0 comments
    n = int(input())
    A = set(map(int, input().split()))
    N = int(input())
    
    for _ in range(0, N):
        cmd = input().split()[0]
        B = set(map(int, input().split()))
        getattr(A, cmd)(B)
        
    print(sum(A))
    
  • + 0 comments

    For Python3 Platform

    n_A = int(input())
    A = set(map(int, input().split()))
    N = int(input())
    for _ in range(N):
        cmd, len = input().split()
        B = set(map(int, input().split()))
        
        if(cmd == "intersection_update"):
            A.intersection_update(B)
        elif(cmd == "update"):
            A |= B
        elif(cmd == "difference_update"):
            A.difference_update(B)
        elif(cmd == "symmetric_difference_update"):
            A ^= B
    
    print(sum(A))