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

  • + 0 comments
    n = int(input())
    s = set(map(int, input().split()))
    
    n_2 = int(input())
    
    for i in range(n_2):
        string = input()
        if "remove" in string or "discard" in string:
            command, value = string.split()
            value = int(value)
            if command == "remove":
                s.remove(value)
            elif command == "discard":
                s.discard(value)
    
        else:
            s.pop()
    print(sum(s))