擅长:python、mysql、java
<p>也许是这样的清单理解:</p>
<pre><code>new_list = [x[:] for x in old_list]
</code></pre>
<p>……尽管如果矩阵的深度超过一个层,列表理解可能不如仅仅使用<code>deepcopy</code>那么优雅。</p>
<p>编辑-如前所述,浅层副本仍将包含对列表中对象的引用。例如。。。</p>
<pre><code>>>> this = [1, 2]
>>> that = [33, 44]
>>> stuff = [this, that]
>>> other = stuff[:]
>>> other
[[1, 2], [33, 44]]
>>> other[0][0] = False
>>> stuff
[[False, 2], [33, 44]] #the same problem as before
>>> this
[False, 2] #original list also changed
>>> other = [x[:] for x in stuff]
>>> other
[[False, 2], [33, 44]]
>>> other[0][0] = True
>>> other
[[True, 2], [33, 44]]
>>> stuff
[[False, 2], [33, 44]] #copied matrix is different
>>> this
[False, 2] #original was unchanged by this assignment
</code></pre>