• + 3 comments

    i still don't understand what they are asking in question , it's messing up my mind

    • + 5 comments

      I took a long time to understand what exactly they were asking. Half the challenge in this question is figuring that out.

      They provide you with a random number N, given by N = int(input()).

      Next they want you to loop through the range of N, and THEN they will provide you with random input() PER loop. You need to record that input, check it with list commands, and then do that command on your list. * if the list command requires additional numbers, they will be provided in the input as well ( eg. insert requires what is being inserted into the list and at what index).

      For example, N = int(input()) # This is the random number provided Lst = [] # this is your list For i in range(N): # here is your loop X = input() # this is the random list command that you need to perform on your lst If x [0] = append # notice i added index, if input length is 3, then you need to specify the index ( eg.input = [‘insert’, ‘inserted number’,’inserted index’] Append to your lst etc

      • + 0 comments

        Thanks! At least now i understand what is being asked.

      • + 0 comments

        Thanks, this explanation was much needed!

      • + 0 comments

        Hey Olivenko,

        Thanks for the explanation. I'm still trying to comprehend this. 1) How do we capture each input subsequent to N, integer? How did you know that after N, there's additoinal input. For a beginner like myself. How do I even understand the beginning?

      • + 0 comments

        Really helpful explanation. Thanks a lot :)

      • + 0 comments

        ya u r right

    • + 11 comments
      N = int(input())
          lis=list()
          for _ in range(N):
              s=input().strip().split(" ")
              if s[0]=="insert":
                  lis.insert(int(s[1]),int(s[2]))
              if s[0]=="print":
                  print(lis)
              if s[0]=="remove":
                  lis.remove(int(s[1]))
              if s[0]=="append":
                  lis.append(int(s[1]))
              if s[0]=="sort":
                  lis.sort()
              if s[0]=="pop":
                  lis.pop()
              if s[0]=="reverse":
                  lis.reverse()
      
      • + 1 comment

        can you plz explain if s[0]=="insert": lis.insert(int(s[1]),int(s[2])) how it works?

        • + 0 comments

          list.insert(position, element)

      • + 1 comment

        Thank you for providing simple solution brother..

        • + 0 comments

          please explain how it stated ??? i am new in programming i dont know

      • + 1 comment

        HI, what does this mean?

        if s[0]=="insert": lis.insert(int(s[1]),int(s[2]))

        • + 0 comments

          simply typcasting it

      • + 1 comment
        if s[0]=="append":
                lis.append(int(s[1]))
                               can you explain this line
        
        • + 0 comments

          here he compared the value of 1st index in s with "append"

          so if user type ------> append 3 , then this 'if' condition will work

          and in lis.append(int(s[1])) he typecasted the 2nd input into

          integer, since he's taking input in form of string .

          NOTE - input() by default take input as string,

      • + 1 comment

        Simplest and best!

        • + 0 comments

          s=input().strip().split(" ") please explain this as im new into programming

      • + 0 comments

        This code might not work if insert is followed by more than 2 inputs or if remove or append is followed by more than 1 input. It does work if the cases all follow that of the example.

      • + 0 comments

        Hey @roy15_5722,

        I am new to python & your solution was easiest to undertstand. I tried it and it worked fine. But i was not able to understand this part "lis.insert(int(s[1]),int(s[2]))". They asked us to insert 5 at 0 index, but by using this command we are inserting both the integers, right? Or if it is otherwise, can you pls explain?

        Thank You

      • + 0 comments

        I prefer this one too, I improved a little bit:

        L = []
        for i in range(N):
            s = input().split(" ")
            arg = list(map(int, s[1:]))
            if s[0] == 'insert':
                L.insert(*arg)
            elif s[0] == 'remove':
                L.remove(*arg)
            elif s[0] == 'append': 
                L.append(*arg)
            elif s[0] == 'sort': 
                L.sort()
            elif s[0] == 'pop':
                L.pop()
            elif s[0] == 'reverse':
                L.reverse()
            else:
                print(L)
        
      • + 1 comment

        Can you pls explain, what does the line

        s=input().strip().split(" ")

        does to the code. I am a noob and I find it hard to understand what does that line mean

        • + 0 comments

          This line tries to strip (the whitespace in front/ at the end) and seperate the command you receive from the input.

          For example, if the command is " append 1". The strip() makes it "append 1", the unnecessary space in front is taken out. Whereas function split(" ") uses space as seperator and split it into two words "append" and "1".

      • + 0 comments

        **Thank You sister **

      • + 0 comments

        Thanks for the code

    • + 1 comment

      Me too. Understanding the intention of it takes me a lot of times.

      • + 0 comments

        Happy to hear that I have some company ;)