Set .discard(), .remove() & .pop()

  • + 0 comments

    n = int(input()) s = set(map(int, input().split()))

    N = int(input())

    for _ in range(N): command = input() if command == 'pop': s.pop() if command.startswith('remove'): s.remove(int(command.split()[1])) if command.startswith('discard'): s.discard(int(command.split()[1]))

    print(sum(s))