when are list link or not ?


 
import bpy
 
 
dataorig1=[]
dataorig1.append([2,-3,-1,2])
data1=[]
data1.append(dataorig1[0])
 
print ()
 
print (' These are list of lists')
print ()
print ('first original  data1 =',dataorig1)
print ('first  data1 =',data1)
print (' dataorig1[0][0]=0 ')
dataorig1[0][0]=0
 
print ('first original  data1 =',dataorig1)
print ('first  data1 =',data1)
print ()
print (' data1[0][0]=2 ')
data1[0][0]=2
print ('first original  data1 =',dataorig1)
print ('first  data1 =',data1)
print ()
print ()
 
 
 
 
<b>print ('new ones')</b>
print ()
dataorig2=[]
dataorig2.append([2,-3,-1,2])
data2=[]
print ('first original  data2 =',dataorig2)
print ('first  data2 =',data2)
print ()
print (' data2.append(list(dataorig2[0])) ') 
data2.append(list(dataorig2[0]))
print (' dataorig2[0][0]=0 ') 
dataorig2[0][0]=0
 
print (' data2[0][0]=2 ') 
data2[0][0]=2
print ()
print ('original  data2 =',dataorig2)
print ('data2 =',data2)
 
 
 

the fitst part of the code just append values from another list but seems to be linked together

and in the second part the lists seems to be independant

difference seems to with the statements

data2.append(list(dataorig2[0]))
and data1.append(dataorig1[0])

the independant one use list(dataorig2[0]) instead of dataorig1[0]!

can someone explain how this works?

thanks
happy 2.5

Lists in in new python behave slightly differently than old.

list=list(list) is two lists. One in the list comprehension that becomes the argument x to list(x). list()'s return list is always a list, in this case – of a list.

When passing lists around as named variables you are mostly passing refences until you explicitly access the contents.

In line with this behavior, see also: slicings.

When you refer by slice notation to a list’s elements, what is returned is a slice object, which is associated with the list, but as a sort of meta-access, where you aren’t accessing the list’s contents yet.