title: Is there a difference between [[float('inf')]*cols]*rows and [[float('inf') for _ in range(cols)] for _ in range(rows)]
body: <p>I just have tried to solve LeetCode's task <a href="https://leetcode.com/problems/01-matrix/" rel="nofollow noreferrer">542. 01 Matrix</a>. After a few attempts, I looked for a solution.</p>
  <pre><code>rows = len(matrix)
      if rows == 0:
          return []
      
      cols = len(matrix[0])
      
      dis = [[float('inf') for _ in range(cols)] for _ in range(rows)]
      
      q = []
      for i in range(rows):
          for j in range(cols):
              if matrix[i][j] == 0:
                  dis[i][j] = 0
                  q.append((i, j))
      
      while len(q) &gt; 0:
          x, y = q.pop(0)
          for (a, b) in ((x-1, y), (x+1, y), (x, y-1), (x, y+1)):
              if 0 &lt;= a &lt; rows and 0 &lt;= b &lt; cols and dis[a][b] &gt; dis[x][y] + 1:
                  dis[a][b] = dis[x][y] + 1
                  q.append((a, b))
      
      return dis
  </code></pre>
  <p>To better understand the code, I changed the line</p>
  <pre><code>dis = [[float('inf') for _ in range(cols)] for _ in range(rows)]
  </code></pre>
  <p>to</p>
  <pre><code>dis = [[float('inf')]*cols]*rows
  </code></pre>
  <p>After the change, the code test failed. What is the difference between the two?</p>