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

  • + 0 comments

    This is for discard, pop and remove method. In this method, I have used getattr techniques as it handles the missing attribute and also it returns the value of an attribute.

    n = int(input()) s = set(map(int, input().split())) N= int(input()) for i in range(N): output = input().split() if len(output)==1: getattr(s,output[0])() try: if len(output)==2: output1 = getattr(s,output[0]) output1(int(output[1])) except: pass

    print(sum(s))