Help! I need a list, not a pointer to it
Sorin Schwimmer
sxn02 at yahoo.com
Tue Nov 21 17:53:04 EST 2006
Hi All,
The following code:
<code>
r=3
c=1
solutions=[]
matrix=[[1.0], [0], [0]]
j=0
while j<c:
i=0
j=0
more=True
while more:
while not matrix[i][j]:
i+=1
i+=1
if i==r:
matrix[0][j]=matrix[i-1][j]
matrix[i-1][j]=0
i=0
j+=1
if j==c: more=False
else:
matrix[i][j]=matrix[i-1][j]
matrix[i-1][j]=0
more=False
print matrix
solutions.append(matrix) # same result with matrix[:]
print solutions
</code>
gives:
[[0], [1.0], [0]]
[[0], [0], [1.0]]
[[1.0], [0], [0]]
[[[1.0], [0], [0]], [[1.0], [0], [0]], [[1.0], [0], [0]]]
(i.e. the last value of matrix, three times)
How can I end up with:
[[0], [1.0], [0]]
[[0], [0], [1.0]]
[[1.0], [0], [0]]
[[[0], [1.0], [0]], [[0], [0], [1.0]], [[1.0], [0], [0]]]
(i.e. each value of matrix)?
I'm on Python 2.4.1, under Linux.
Thanks,
Sorin
____________________________________________________________________________________
Sponsored Link
Online degrees - find the right program to advance your career.
www.nextag.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20061121/b621cf5c/attachment.html>
More information about the Python-list
mailing list