title: Adding Padding to a 2D Array in Python
body: <p>How can I add padding consisting of zeros to a 2D array (without using any additional modules)?</p>
  <p>For example, I have the following grid:</p>
  <p>1 0 1 1<br>
  0 1 1 0<br>
  1 0 0 1<br>
  1 0 1 1<br></p>
  <p>I would like the output to be:</p>
  <p>0 0 0 0 0 0<br>
  0 1 0 1 1 0<br>
  0 0 1 1 0 0<br>
  0 1 0 0 1 0<br>
  0 1 0 1 1 0<br>
  0 0 0 0 0 0<br></p>
  <p>I have tried the following code and its working, but I would like to know if there is a better way to achieve this.</p>
  <pre><code>def padded_grid(grid):
  
      gridpadding = []
  
      extrarow = [0] * (len(grid) + 2)
      gridpadding.append(extrarow)
      for row in grid:
          row.insert(0, 0)
          row.append(0)
          gridpadding.append(row)
      gridpadding.append(extrarow)
  
      return gridpadding
  </code></pre>