View Single Post
Old Dec 12th, 2004, 10:55 PM   #7
JoeUser
Newbie
 
Join Date: Dec 2004
Posts: 8
Rep Power: 0 JoeUser is on a distinguished road
Yes I know! But take this piece of code for example
>>> a = {'a':1,'b':2,'c':3}
>>> b = a
>>> print a
{'a': 1, 'c': 3, 'b': 2}
>>> b['a'] = 9999
>>> print a
{'a': 9999, 'c': 3, 'b': 2}
When you assign the value of one array to the value of another, really you are just creating another name for the same array. See how when I modified b, a was also modified? It's like calling

Arrays in python act strangely, they act more like methods than variables. The question is, how do I copy one array into an independent array? With normal arrays (such as a = [1,2,3]), you would do this by "splicing" it with b = a[:] . But with definition arrays (a = {'a':1,'b':2,'c':3}) splice doesn't work.
JoeUser is offline   Reply With Quote