help with something that ought to be simple
Matthew Nobes
manobes at fraser.sfu.ca
Wed Oct 24 19:53:24 EDT 2001
Hello all,
I am trying to do something that ought to be very simple, yet for
some reason isn't.
What I want to do it the following. Take a list of lists, in the
following form
[[0,0,0,0],[1,0,0,0],...,]
and preform some operations on it.
So I wrote a litte script to do this, here's the first bit
def del_2(rho,input,output):
output=[[0,0,0,0]]
for i in input:
i[rho-1]=1
output.append(i)
so far so good. This takes the input and appends it, slightly
modified to the output.
Now here comes the problem. I want to add some more stuff to the
output. Here's what I try to do:
temp=[]
for i in output[2:]:
temp.append(i)
for i in temp:
i[rho-1]=i[rho-1]-1
for i temp:
output.append(i)
return output
I define temp precisly so that I don't mess with output. What I
want to do is do some stuff to temp, then append that onto the
output from before. BUT*** everything I do to temp also get's
done to output. This ends up makeing the earlier stuff get
mucked up
a concrete example:
I input rho=2 and input=[[0,0,0,0],[1,0,0,0]]
after the first step output is
[[0,0,0,0],[0,1,0,0],[1,1,0,0]]
This is what I want. Now I call that temp, and take the last
entry and make it [1,0,0,0].
Now I did this to temp. So I should be able to now append this
to output and my result *SHOULD* be
[[0,0,0,0],[0,1,0,0],[1,1,0,0],[1,0,0,0]]
but instead the operation on temp also gets preformed on output
and I get
[[0,0,0,0],[0,1,0,0],[1,0,0,0],[1,0,0,0]]
So my question is how do I stop this from happening? I must be
something extremely simple, so sorry in advance for asking
something silly...
--
``We may feel that at last, unlike all previous generations, we
have found certitude. They thought so too'' -Robert Conquest
Matthew Nobes, c/o Physics Dept. Simon Fraser University, 8888 University
Drive Burnaby, B.C., Canada, http://www.sfu.ca/~manobes
More information about the Python-list
mailing list