We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#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.
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))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Set Mutations
You are viewing a single comment's thread. Return to all 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))