Set Mutations

Sort by

recency

|

809 Discussions

|

  • + 0 comments

    Here's my code:

    al = int(input())
    a = set(list(map(int, input().split()))[:al])
    for _ in range(int(input())):
        c, l = input().split()
        if not hasattr(set, c):
            continue
        getattr(a, c)(set(list(map(int, input().split()))[:int(l)]))
    print(sum(a))
    
  • + 0 comments

    A = int(input()) el_A = set(map(int, input().split())) for i in range(int(input())): command = input().split() set_b = set(map(int, input().split())) if command[0] == 'update': el_A.update(set_b) elif command[0] == 'intersection_update': el_A.intersection_update(set_b) elif command[0] == 'difference_update': el_A.difference_update(set_b) elif command[0] == 'symmetric_difference_update': el_A.symmetric_difference_update(set_b) print(sum(el_A))

  • + 0 comments
    N = input()
    a = set(map(int,input().split()))
    
    for i in range(int(input())):
        t = list(input().split())
        r = set(map(int,input().split()))
        eval(f"a.{t[0]}(r)")
    print(sum(a))
    
  • + 0 comments
    a = int(input())
    A = set(map(int, input().split()))
    N = int(input())
    operations = {'intersection_update': A.intersection_update, 'update': A.update, 'symmetric_difference_update': A.symmetric_difference_update, 'difference_update': A.difference_update}
    for _ in range(N):
        name, _ = input().split()
        B = list(map(int, input().split()))
        operations[name](B)
    print(sum(A))
    
  • + 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):
        command = input().split()
        B = set(map(int, input().split()))
        if command[0] == "intersection_update":
            A.intersection_update(B)
        if command[0] == "update":
            A.update(B)
        if command[0] == "symmetric_difference_update":
            A.symmetric_difference_update(B)
        if command[0] == "difference_update":
            A.difference_update(B)
    
    print(sum(A))