Set Mutations

Sort by

recency

|

829 Discussions

|

  • + 0 comments

    n = int(input()) s = set(map(int,input().split())) its = int(input()) for i in range(its): ops = input().split() opn = ops[0] opt = int(ops[1]) ms = set(map(int,input().split())) if opn == "update": s.update(ms) elif opn == "intersection_update": s.intersection_update(ms) elif opn == "symmetric_difference_update": s.symmetric_difference_update(ms) else: s.difference_update(ms)

    print(sum(s))

  • + 0 comments
    a=int(input())
    b=set(map(int, input().split()))
    c=int(input())
    for _ in range(c):
        d,_=input().split()
        other_set = set(map(int, input().split()))
        if d=="intersection_update":
            b.intersection_update(other_set)
        elif d=="update":
            b.update(other_set)
        elif d=="symmetric_difference_update":
            b.symmetric_difference_update(other_set)
        elif d=="difference_update":
            b.difference_update(other_set)
    print(sum(b))
    
  • + 0 comments

    Here is my code

    n, A = input(), set(map(int, input().split()))
    
    for _ in range( int( input() ) ):
        operation_name = input().split()[0]
        B = set(map(int, input().split()))
        operation = getattr(A, operation_name)(B)
        
        # operation(B)
        
        
    print(sum(A))
    
  • + 0 comments

    here you go

    len_A = map(int, input())
    A= set(map(int, input().split()))
    N = int(input())
    for i in range(0, N):
        command, length = input().split()
        Sec_set = set(map(int, input().split()))
        eval("A."+command+"(Sec_set)")
    print(sum(A))
    
  • + 0 comments

    logic for this code