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

  • + 0 comments
    n = int(input())
    s = set(map(int, input().split()))
    N = int(input())
    
    for _ in range(N):
        command_list = list(map(str, input().split()))
        if command_list[0].lower() == 'pop':
            s.pop()
        elif command_list[0].lower() == 'discard':
            s.discard(int(command_list[1]))
        elif command_list[0].lower() == 'remove':
            try:
                s.remove(int(command_list[1]))
            except None:
                pass
    print(sum(s))