[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>&lt;code&gt;<br>r=3<br>c=1<br>solutions=[]<br>matrix=[[1.0], [0], \
[0]]<br>j=0<br>while j&lt;c:<br>&nbsp; i=0<br>&nbsp; j=0<br>&nbsp; \
more=True<br>&nbsp; while more:<br>&nbsp;&nbsp;&nbsp; while not \
matrix[i][j]:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i+=1<br>&nbsp;&nbsp;&nbsp; \
i+=1<br>&nbsp;&nbsp;&nbsp; if i==r:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
matrix[0][j]=matrix[i-1][j]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
matrix[i-1][j]=0<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
i=0<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; j+=1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if j==c: \
more=False<br>&nbsp;&nbsp;&nbsp; else:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
matrix[i][j]=matrix[i-1][j]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
matrix[i-1][j]=0<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; more=False<br>&nbsp; print \
matrix<br>&nbsp;  solutions.append(matrix) # same result with matrix[:]<br>print \
solutions<br>&lt;/code&gt;<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