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
|
933 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_line = input().split() if command_line[0] == 'pop': s.pop() elif command_line[0] == 'remove': s.remove(int(command_line[-1])) elif command_line[0] == 'discard': s.discard(int(command_line[-1])) print(sum(s))
Yeah you have to use Python 3, because there pop pops the first element out of the set. pypy3 does the last.
n = int(input()) s = set(map(int, input().split())) N= int(input()) for i in range(N): inp = input().split() call= getattr(s, inp[0]) call(*[int(j) for j in inp[1:]])
print(sum(s))
This challenge is seemingly broken EDIT: It is pypy3 that handles pop() differently, make sure to use Python3
for _ in range(int(input())): cmd, *arg = input().split() eval(f's.{cmd}(*{list(map(int, arg))})') print(sum(s))