Stack reverse matrix












-1















I am trying to make stack by matrix and reverse stack matrix and show it like sit in a box:



stack=
x=int(input("Enter size of stack :"))
Top=-1
for i in range(x):
Top+=1
stack.append(int(input("Top is in {} positionnEnter stack item :".format(i))))
print("stack=",stack)
print("|",stack[Top],"|","==>Top")
for i in range(len(stack)-1):
Top-=1
print("|",stack[Top],"|")

rev=
rev_top=-1
for x in range(-1,-len(stack)-1,-1):
rev.append(stack[x])
rev_top+=1
print("stack recerse =",rev)


The put:



|7 4 5 |==>Top
|3 5 9 |
|2 4 5 |
|4 5 2 |


I want it's reverse be like this



|4 5 2 | ==>Top
|2 4 5 |
|3 5 9 |
|7 4 5 |


So each time I pop row the top position moves to the next of it until stack Empty.










share|improve this question





























    -1















    I am trying to make stack by matrix and reverse stack matrix and show it like sit in a box:



    stack=
    x=int(input("Enter size of stack :"))
    Top=-1
    for i in range(x):
    Top+=1
    stack.append(int(input("Top is in {} positionnEnter stack item :".format(i))))
    print("stack=",stack)
    print("|",stack[Top],"|","==>Top")
    for i in range(len(stack)-1):
    Top-=1
    print("|",stack[Top],"|")

    rev=
    rev_top=-1
    for x in range(-1,-len(stack)-1,-1):
    rev.append(stack[x])
    rev_top+=1
    print("stack recerse =",rev)


    The put:



    |7 4 5 |==>Top
    |3 5 9 |
    |2 4 5 |
    |4 5 2 |


    I want it's reverse be like this



    |4 5 2 | ==>Top
    |2 4 5 |
    |3 5 9 |
    |7 4 5 |


    So each time I pop row the top position moves to the next of it until stack Empty.










    share|improve this question



























      -1












      -1








      -1








      I am trying to make stack by matrix and reverse stack matrix and show it like sit in a box:



      stack=
      x=int(input("Enter size of stack :"))
      Top=-1
      for i in range(x):
      Top+=1
      stack.append(int(input("Top is in {} positionnEnter stack item :".format(i))))
      print("stack=",stack)
      print("|",stack[Top],"|","==>Top")
      for i in range(len(stack)-1):
      Top-=1
      print("|",stack[Top],"|")

      rev=
      rev_top=-1
      for x in range(-1,-len(stack)-1,-1):
      rev.append(stack[x])
      rev_top+=1
      print("stack recerse =",rev)


      The put:



      |7 4 5 |==>Top
      |3 5 9 |
      |2 4 5 |
      |4 5 2 |


      I want it's reverse be like this



      |4 5 2 | ==>Top
      |2 4 5 |
      |3 5 9 |
      |7 4 5 |


      So each time I pop row the top position moves to the next of it until stack Empty.










      share|improve this question
















      I am trying to make stack by matrix and reverse stack matrix and show it like sit in a box:



      stack=
      x=int(input("Enter size of stack :"))
      Top=-1
      for i in range(x):
      Top+=1
      stack.append(int(input("Top is in {} positionnEnter stack item :".format(i))))
      print("stack=",stack)
      print("|",stack[Top],"|","==>Top")
      for i in range(len(stack)-1):
      Top-=1
      print("|",stack[Top],"|")

      rev=
      rev_top=-1
      for x in range(-1,-len(stack)-1,-1):
      rev.append(stack[x])
      rev_top+=1
      print("stack recerse =",rev)


      The put:



      |7 4 5 |==>Top
      |3 5 9 |
      |2 4 5 |
      |4 5 2 |


      I want it's reverse be like this



      |4 5 2 | ==>Top
      |2 4 5 |
      |3 5 9 |
      |7 4 5 |


      So each time I pop row the top position moves to the next of it until stack Empty.







      python list matrix stack reverse






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 24 '18 at 2:22









      martineau

      66.2k989178




      66.2k989178










      asked Nov 24 '18 at 0:37









      SaLeHSaLeH

      143




      143
























          1 Answer
          1






          active

          oldest

          votes


















          0














          First, instead of your relatively long code for reversing elements in the stack list



          rev=
          rev_top=-1
          for x in range(-1,-len(stack)-1,-1):
          rev.append(stack[x])
          rev_top+=1


          you may use built-in function reversed():



          rev = list(reversed(stack))         # list() is used because reversed() returns an iterator


          or - even better - reverse the stack list in place with the reverse() method:



          stack.reverse()  # Note: Do NOT use something as stack = stack.reverse() - you will get Null


          Now you may use the same code from your program to nice print the reversed stack, i. e. the part



          top = -1
          print("|", stack[top], "|", "==>Top")
          for i in range(len(stack) - 1):
          top -= 1
          print("|", stack[top], "|")


          (I put some space symbols to it and changed the variable name Top to top to be in the concordance with PEP 8 - Style Guide for Python Code.)






          share|improve this answer


























          • I know I can use method reverse but I don't want to use it

            – SaLeH
            Nov 24 '18 at 9:32











          • Because of ...?

            – MarianD
            Nov 24 '18 at 14:43











          • It an exercise 😅, and I have been answer it , thx you

            – SaLeH
            Nov 24 '18 at 15:21











          • Why don´t perform smarter exercises than implement build-in functions in so poor way? Why ask a question if answers don't interest you?

            – MarianD
            Nov 24 '18 at 17:19











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454231%2fstack-reverse-matrix%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          First, instead of your relatively long code for reversing elements in the stack list



          rev=
          rev_top=-1
          for x in range(-1,-len(stack)-1,-1):
          rev.append(stack[x])
          rev_top+=1


          you may use built-in function reversed():



          rev = list(reversed(stack))         # list() is used because reversed() returns an iterator


          or - even better - reverse the stack list in place with the reverse() method:



          stack.reverse()  # Note: Do NOT use something as stack = stack.reverse() - you will get Null


          Now you may use the same code from your program to nice print the reversed stack, i. e. the part



          top = -1
          print("|", stack[top], "|", "==>Top")
          for i in range(len(stack) - 1):
          top -= 1
          print("|", stack[top], "|")


          (I put some space symbols to it and changed the variable name Top to top to be in the concordance with PEP 8 - Style Guide for Python Code.)






          share|improve this answer


























          • I know I can use method reverse but I don't want to use it

            – SaLeH
            Nov 24 '18 at 9:32











          • Because of ...?

            – MarianD
            Nov 24 '18 at 14:43











          • It an exercise 😅, and I have been answer it , thx you

            – SaLeH
            Nov 24 '18 at 15:21











          • Why don´t perform smarter exercises than implement build-in functions in so poor way? Why ask a question if answers don't interest you?

            – MarianD
            Nov 24 '18 at 17:19
















          0














          First, instead of your relatively long code for reversing elements in the stack list



          rev=
          rev_top=-1
          for x in range(-1,-len(stack)-1,-1):
          rev.append(stack[x])
          rev_top+=1


          you may use built-in function reversed():



          rev = list(reversed(stack))         # list() is used because reversed() returns an iterator


          or - even better - reverse the stack list in place with the reverse() method:



          stack.reverse()  # Note: Do NOT use something as stack = stack.reverse() - you will get Null


          Now you may use the same code from your program to nice print the reversed stack, i. e. the part



          top = -1
          print("|", stack[top], "|", "==>Top")
          for i in range(len(stack) - 1):
          top -= 1
          print("|", stack[top], "|")


          (I put some space symbols to it and changed the variable name Top to top to be in the concordance with PEP 8 - Style Guide for Python Code.)






          share|improve this answer


























          • I know I can use method reverse but I don't want to use it

            – SaLeH
            Nov 24 '18 at 9:32











          • Because of ...?

            – MarianD
            Nov 24 '18 at 14:43











          • It an exercise 😅, and I have been answer it , thx you

            – SaLeH
            Nov 24 '18 at 15:21











          • Why don´t perform smarter exercises than implement build-in functions in so poor way? Why ask a question if answers don't interest you?

            – MarianD
            Nov 24 '18 at 17:19














          0












          0








          0







          First, instead of your relatively long code for reversing elements in the stack list



          rev=
          rev_top=-1
          for x in range(-1,-len(stack)-1,-1):
          rev.append(stack[x])
          rev_top+=1


          you may use built-in function reversed():



          rev = list(reversed(stack))         # list() is used because reversed() returns an iterator


          or - even better - reverse the stack list in place with the reverse() method:



          stack.reverse()  # Note: Do NOT use something as stack = stack.reverse() - you will get Null


          Now you may use the same code from your program to nice print the reversed stack, i. e. the part



          top = -1
          print("|", stack[top], "|", "==>Top")
          for i in range(len(stack) - 1):
          top -= 1
          print("|", stack[top], "|")


          (I put some space symbols to it and changed the variable name Top to top to be in the concordance with PEP 8 - Style Guide for Python Code.)






          share|improve this answer















          First, instead of your relatively long code for reversing elements in the stack list



          rev=
          rev_top=-1
          for x in range(-1,-len(stack)-1,-1):
          rev.append(stack[x])
          rev_top+=1


          you may use built-in function reversed():



          rev = list(reversed(stack))         # list() is used because reversed() returns an iterator


          or - even better - reverse the stack list in place with the reverse() method:



          stack.reverse()  # Note: Do NOT use something as stack = stack.reverse() - you will get Null


          Now you may use the same code from your program to nice print the reversed stack, i. e. the part



          top = -1
          print("|", stack[top], "|", "==>Top")
          for i in range(len(stack) - 1):
          top -= 1
          print("|", stack[top], "|")


          (I put some space symbols to it and changed the variable name Top to top to be in the concordance with PEP 8 - Style Guide for Python Code.)







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 24 '18 at 4:27

























          answered Nov 24 '18 at 4:11









          MarianDMarianD

          4,28761331




          4,28761331













          • I know I can use method reverse but I don't want to use it

            – SaLeH
            Nov 24 '18 at 9:32











          • Because of ...?

            – MarianD
            Nov 24 '18 at 14:43











          • It an exercise 😅, and I have been answer it , thx you

            – SaLeH
            Nov 24 '18 at 15:21











          • Why don´t perform smarter exercises than implement build-in functions in so poor way? Why ask a question if answers don't interest you?

            – MarianD
            Nov 24 '18 at 17:19



















          • I know I can use method reverse but I don't want to use it

            – SaLeH
            Nov 24 '18 at 9:32











          • Because of ...?

            – MarianD
            Nov 24 '18 at 14:43











          • It an exercise 😅, and I have been answer it , thx you

            – SaLeH
            Nov 24 '18 at 15:21











          • Why don´t perform smarter exercises than implement build-in functions in so poor way? Why ask a question if answers don't interest you?

            – MarianD
            Nov 24 '18 at 17:19

















          I know I can use method reverse but I don't want to use it

          – SaLeH
          Nov 24 '18 at 9:32





          I know I can use method reverse but I don't want to use it

          – SaLeH
          Nov 24 '18 at 9:32













          Because of ...?

          – MarianD
          Nov 24 '18 at 14:43





          Because of ...?

          – MarianD
          Nov 24 '18 at 14:43













          It an exercise 😅, and I have been answer it , thx you

          – SaLeH
          Nov 24 '18 at 15:21





          It an exercise 😅, and I have been answer it , thx you

          – SaLeH
          Nov 24 '18 at 15:21













          Why don´t perform smarter exercises than implement build-in functions in so poor way? Why ask a question if answers don't interest you?

          – MarianD
          Nov 24 '18 at 17:19





          Why don´t perform smarter exercises than implement build-in functions in so poor way? Why ask a question if answers don't interest you?

          – MarianD
          Nov 24 '18 at 17:19


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454231%2fstack-reverse-matrix%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Lallio

          Unable to find Lightning Node

          Futebolista