Set Mutations

  • + 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))