[prev in list] [next in list] [prev in thread] [next in thread]
List: python-list
Subject: Help! I need a list, not a pointer to it
From: Sorin Schwimmer <sxn02 () yahoo ! com>
Date: 2006-11-21 22:53:04
Message-ID: 20061121225304.67695.qmail () web56001 ! mail ! re3 ! yahoo ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
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
[Attachment #5 (text/html)]
<html><head><style type="text/css"><!-- DIV {margin:0px;} \
--></style></head><body><div style="font-family:times new roman, new york, times, \
serif;font-size:12pt"><div>Hi All,<br><br>The following \
code:<br><br><code><br>r=3<br>c=1<br>solutions=[]<br>matrix=[[1.0], [0], \
[0]]<br>j=0<br>while j<c:<br> i=0<br> j=0<br> \
more=True<br> while more:<br> while not \
matrix[i][j]:<br> i+=1<br> \
i+=1<br> if i==r:<br> \
matrix[0][j]=matrix[i-1][j]<br> \
matrix[i-1][j]=0<br> \
i=0<br> j+=1<br> if j==c: \
more=False<br> else:<br> \
matrix[i][j]=matrix[i-1][j]<br> \
matrix[i-1][j]=0<br> more=False<br> print \
matrix<br> solutions.append(matrix) # same result with matrix[:]<br>print \
solutions<br></code><br><br>gives:<br>[[0], [1.0], [0]]<br>[[0], [0], \
[1.0]]<br>[[1.0], [0], [0]]<br>[[[1.0], [0], [0]], [[1.0], [0], [0]], [[1.0], [0], \
[0]]]<br>(i.e. the last value of matrix, three times)<br><br>How can I end up \
with:<br>[[0], [1.0], [0]]<br>[[0], [0], [1.0]]<br>[[1.0], [0], [0]]<br>[[[0], [1.0], \
[0]], [[0], [0], [1.0]], [[1.0], [0], [0]]]<br>(i.e. each value of \
matrix)?<br><br>I'm on Python 2.4.1, under \
Linux.<br><br>Thanks,<br>Sorin<br></div></div><br>
<font color="666666"><font size="2"><hr size=1>Sponsored \
Link</font></font><br><br>Mortgage rates near 39yr lows. $420,000 Mortgage for \
$1,399/mo - <a href="http://www.lowermybills.com/lre/index.jsp?sourceid=lmb-9132-16414&moid=4116">Calculate \
new house payment</a></body></html>
--
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic