You are viewing a single comment's thread. Return to all comments →
This works in Python3
n = int(input()) s = set(map(int, input().split())) N = int(input())
for _ in range(N): command = input().split()
if command[0] == 'pop': s.pop() elif command[0] == 'discard': s.discard(int(command[1])) else: s.remove(int(command[1]))
print(sum(s))
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 .discard(), .remove() & .pop()
You are viewing a single comment's thread. Return to all comments →
This works in Python3
n = int(input()) s = set(map(int, input().split())) N = int(input())
for _ in range(N): command = input().split()
print(sum(s))