Lists – Python | Hackerrank Solution

Lists – Python | Hackerrank Solution

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[0]

    # extraction of arguments 
    args = s[1:]

    # condition
    if command !="print":
        # here we adding strings of commands
        command += "("+ ",".join(args) +")"

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)).

Leave a Reply

Your email address will not be published. Required fields are marked *