list links itself?

I noticed that lists link themselves… got any solutions (I don’t want this effect)?

This code:


a = [0,1,2]
b = a
b[2] = 0
print a

returns:

[0,1,0]

srry that I posted I know it now you have to say:
b = a[:]

heh, but you inspire me to try something fun

[in the python interactive intrepreter]

>>> a = range(3)
>>> a[2] = a
>>> a
[0, 1, [...]]
>>> for blah in a:print blah
...
0
1
[0, 1, [...]]
>>>

looks like python is too good for my own good… well it’s cool a list can contain itself

Mutable object always use references for assignement and passing parameters, be careful, check you really are working on what you think you are working on.

Martin

You tell me or him?

That was a general advice :slight_smile:

<applies to me too when I’m coding during late hours> :stuck_out_tongue:

Martin