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.
Set .discard(), .remove() & .pop()
Set .discard(), .remove() & .pop()
Sort by
recency
|
990 Discussions
|
Please Login in order to post a comment
n = int(input()) s = set(map(int, input().split()))
N = int(input())
for i in range(N): command = input().split() if command[0] == 'pop': s.pop() elif command[0] == 'remove': s.remove(int(command[1])) elif command[0] == 'discard': s.discard(int(command[1]))
print(sum(s))
n = int(input()) s = set(map(int, input().split())) N=int(input()) for i in range(N): res=input() if res=="pop": s.pop() elif "remove" in res: s.remove(int(res[len(res)-1])) else: s.discard(int(res[len(res)-1])) print(sum(s))
PLEASE CHANGE THE CODE TO PYTHON 3. YOU WILL NEVER GET THE CORRECT ANSWER IN PYPY3