In this HackerRank Set Mutations problem solution, You are given a set A and N number of other sets. These N number of sets have to perform some specific mutation operations on set A. Your task is to execute those operations and print the sum of elements from set A.

HackerRank Set Mutations in python problem solution

HackerRank Set Mutations in python problem solution

# Enter your code here. Read input from STDIN. Print output to STDOUT
raw_input()
set1=set(map(int,raw_input().split()))
n=int(raw_input())


for i in range(0,n):
   
    op=raw_input().split()[0]
    set2=set(map(int,raw_input().split()))
    if op=="intersection_update":
        #print "intersection"
        set1.intersection_update(set2)
        #print set1
    if op=="update":
        #print "update"
        set1.update(set2)
        #print set1
    if op=="difference_update":
        #print "difference"
        set1.difference_update(set2)
        #print set1
    if op=="symmetric_difference_update":
        #print "symmetric_difference_update"
        set1.symmetric_difference_update(set2)
        #print set1
    
print sum(set1)