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
|
1087 Discussions
|
Please Login in order to post a comment
For Python3 Platform
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])) elif command[0]=="remove": if int(command[1]) in s: s.remove(int(command[1]))
print (sum(s))
Code only can be run in python3. Will have wrong answer in Pypy3
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])) elif command[0]=="remove": if int(command[1]) in s: s.remove(int(command[1]))
print (sum(s))