You are viewing a single comment's thread. Return to all comments →
A = int(input()) set_A = set(map(int,input().split())) B = int(input()) for _ in range(B): command = list(map(str, input().split())) set_B = set(map(int,input().split())) if command[0].lower() == 'intersection_update': set_A &= set_B elif command[0].lower() == 'update': set_A |= set_B elif command[0].lower() == 'symmetric_difference_update': set_A ^= set_B elif command[0].lower() == 'difference_update': set_A -= set_B print(sum(set_A))
for _ in range(N): command = input().split() if command[0] == 'update': A.update(set(map(int, input().split()))) elif command[0] == 'intersection_update': A.intersection_update(set(map(int, input().split()))) elif command[0] == 'difference_update': A.difference_update(set(map(int, input().split()))) elif command[0] == 'symmetric_difference_update': A.symmetric_difference_update(set(map(int, input().split())))
print(sum(A))
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Set Mutations
You are viewing a single comment's thread. Return to all comments →
for _ in range(N): command = input().split() if command[0] == 'update': A.update(set(map(int, input().split()))) elif command[0] == 'intersection_update': A.intersection_update(set(map(int, input().split()))) elif command[0] == 'difference_update': A.difference_update(set(map(int, input().split()))) elif command[0] == 'symmetric_difference_update': A.symmetric_difference_update(set(map(int, input().split())))
print(sum(A))