We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
n = int(input())
s = set(map(int, input().split()))
n_2 = int(input())
for i in range(n_2):
string = input()
try:
if "remove" in string or "discard" in string:
command, value = string.split()
value = int(value)
if command == "remove":
s.remove(value)
elif command == "discard":
s.discard(value)
Set .discard(), .remove() & .pop()
You are viewing a single comment's thread. Return to all comments →
For pypy3
n = int(input()) s = set(map(int, input().split()))
n_2 = int(input())
for i in range(n_2): string = input() try: if "remove" in string or "discard" in string: command, value = string.split() value = int(value) if command == "remove": s.remove(value) elif command == "discard": s.discard(value)
print(sum(s))