title: Mirroring rows in matrix with loops/recursion?
body: <p>Given some matrix, I need to mirror all the rows in the matrix. For example </p>
  
  <pre><code>[[2, 1],
  [4, 3]]
  </code></pre>
  
  <p>would become </p>
  
  <pre><code>[[1, 2],
  [3, 4]]
  </code></pre>
  
  <p>I managed to do it for the (2 x 2)-case. But I'm having trouble mirroring something like this:</p>
  
  <pre><code>[[1, 2, 3, 4],
  [1, 2, 3, 4]]
  </code></pre>
  
  <p>This has to become</p>
  
  <pre><code>[[4, 3, 2, 1],
  [4, 3, 2, 1]]
  </code></pre>
  
  <p>I want to do this with loops/recursion. If I use recursion, I would probably have as basic step that the inner most elements get swapped first, and then from here on we would make the matrix bigger by also including the outer elements and swapping them too. However, I'm having trouble with the recursion step. After having swapped the inner most elements, I want to include the next to inner most elements in the matrix, and swap them too, and then continue like this until we reach the outer elements. How can this be implemented in code? This is what I did so far:</p>
  
  <pre><code>matrix = [[1, 2, 3, 4],
            [1, 2, 3, 4]]
  
  def mirror(matrix):
      # This corresponds to the basic step. The two inner most elements get swapped.
      if len(matrix) == 2:
          for i in range(len(matrix)):
              for j in range(len(matrix)):
                  # Store one element in a temporal variable
                  temp = matrix[i][j]
                  matrix[i][j] = matrix[i][len(matrix) - 1]
                  matrix[i][len(matrix)-1] = temp
                  return matrix
  
      else:
          # Recursion step
          for i in range(len(matrix)):
              for j in range(len(matrix)):
                  return (matrix + mirror(matrix[(len(matrix) // 2) - 1 : len(matrix)]))
  </code></pre>
  
  <p>The recursion step is wrong I think. I tried using the slice operator, but I'm not sure how this should be done correctly. Any help with this problem would be appreciated.</p>