擅长:python、mysql、java
<p>您的函数<code>copy</code>不正确。此代码:</p>
<pre><code>def copy(A):
height=len(A)
width=len(A[0])
newA=[]
row=[]
for row in range(0,height):
for col in range(0,width):
if A[row][col]==0:
newA+=[0]
elif A[row][col]==1:
newA+=[1]
return newA
a = [
[1, 1, 0],
[0, 1, 1],
]
print a
print copy(a)
</code></pre>
<p>打印此:</p>
^{pr2}$
<p>如您所见,它不包含子列表,因此它尝试迭代整数。在</p>
<p>我用<code>copy.deepcopy</code>就可以了。在</p>