Input Format
The first line contains the number of elements in set .
The second line contains the space separated list of elements in set .
The third line contains integer , the number of other sets.
The next  lines are divided into  parts containing two lines each.
The first line of each part contains the space separated entries of the operation name and the length of the other set.
The second line of each part contains space separated list of elements in the other set.
 len(set(A)) 
 len(otherSets) 
Output Format
Output the sum of elements in set .

hackerrank set mutations problem solution in python programming

Problem solution in Python 3 programming language.

a = int(input())
A = set(map(int, input().split()))
for i in range(int(input())):
    s, b = input().split()
    if s == 'intersection_update':
        A &= set(map(int, input().split()))
    elif s == 'update':
        A |= set(map(int, input().split()))
    elif s == 'symmetric_difference_update':
        A ^= set(map(int, input().split()))
    else:
        A -= set(map(int, input().split()))
print(sum(A))

Second solution

# Enter your code here. Read input from STDIN. Print output to STDOUT
if __name__ == '__main__':
    (_, A) = (int(input()),set(map(intinput().split())))
    B = int(input())
    for _ in range(B):
        (command, newSet) = (input().split()[0],set(map(intinput().split())))
        getattr(A, command)(newSet)
    print (sum(A))

Problem solution in Python 2 programming language.

a = int(raw_input())
A = set(map(int, raw_input().split()))
for i in range(int(raw_input())):
    s, b = raw_input().split()
    if s == 'intersection_update':
        A &= set(map(int, raw_input().split()))
    elif s == 'update':
        A |= set(map(int, raw_input().split()))
    elif s == 'symmetric_difference_update':
        A ^= set(map(int, raw_input().split()))
    else:
        A -= set(map(int, raw_input().split()))
print sum(A)