Set Mutations

  • + 0 comments

    #What separates my solution is the usage of eval function: which can dynamically execute any text representing a particular function. Most solutions set a conditional logic to determine which function to run.

    A_len = int(input()) A_set = set( map(int, input().split(" ")) )

    N_len = int(input()) for n in range(N_len): #iteration of 0 to Nth X_str = input().split(" ") X_fx_str = X_str[0] X_set =set( map(int, input().split(" ")) )
    eval( f"A_set.{X_fx_str}(X_set)" ) #This is where the eval function used

    print(sum(A_set))