Here I am going to share the solution to the problem of hackerrank python practice challenge.
# number of query n = int(input()) # list to store the data element lst =  # loop through n times for i in range(n): # splited input strings s = input().split() # command extraction from splited strings command = s # extraction of arguments args = s[1:] # condition if command !="print": # here we adding strings of commands command += "("+ ",".join(args) +")" eval("lst."+command) else: print(lst)
in the condition block, we are first checking command is print or not. So when the command is not print. By using eval() function we evaluating as eval(lst.command_name(args_if_any)).