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

  • + 0 comments
    n = int(input())
    s = set(map(int, input().split()))
    
    n1 = int(input())
    
    for i in range(n1):
        method = input().split()
        
        if len(method) == 1 and method[0]=="pop":
            s.pop()
        elif method[0] == "remove" :
            s.remove(int(method[1]))
        elif method[0] == "discard":
            s.discard(int(method[1]))
    
    print(sum(s))