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
|
1099 Discussions
|
Please Login in order to post a comment
n = int(input()) s = set(map(int, input().split())) ctr = int(input())
for _ in range(ctr): actions = input().split() method = getattr(s, actions[0])
print(sum(s))
if name == 'main': n = int(input()) myset = set(map(int,input().split())) N = int(input())
for _ in range(N): cmd, *args = input().split() getattr(myset,cmd)(*map(int,args)) print(sum(myset))
If pop() removes an arbitrary item from the set, how can the answer be determinative?
set.pop is meh, so convert to list and pop consistently