-4

so I have this matrix:

matrix = [ [1, 2, 3],
           [4, 5, 6],
           [7, 8, 9]
         ]

And I want to remove the last row, so it return me something like this:

matrix = [ [1, 2, 3],
           [4, 5, 6]
         ]

P.S. I cant use Numpy.

  • 1
    Does this answer your question? [How to remove an element from a list by index](https://stackoverflow.com/questions/627435/how-to-remove-an-element-from-a-list-by-index) – Countour-Integral Jan 19 '21 at 20:09
  • try `del matrix[-1]` – Moinuddin Quadri Jan 19 '21 at 20:17
  • Please repeat [on topic](https://stackoverflow.com/help/on-topic) and [how to ask](https://stackoverflow.com/help/how-to-ask) from the [intro tour](https://stackoverflow.com/tour). Stack Overflow is not intended to replace existing tutorials and documentation. Removing an item from a list is covered in any tutorial on lists. – Prune Jan 19 '21 at 20:17

1 Answers1

0
matrix = [ [1, 2, 3],
           [4, 5, 6],
           [7, 8, 9]
         ]
matrix[:-1]

This gives [[1, 2, 3], [4, 5, 6]] back

So what you can do is:

matrix = matrix[:-1]
arjow
  • 74
  • 3