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

  • + 0 comments

    I also wanted to use lamda but realized there was a problem I saw before which also required dynamic function call like this. Studied getattr()() workings and here is a much much simpler way

    N = int(input())
    
    for _ in range(N):
        COMMAND = input().split()
        if len(COMMAND) == 1:
            getattr(s, COMMAND[0])()
        else:
            getattr(s, COMMAND[0])(int(COMMAND[1]))
    print(sum(s))