[Python.NET] Modifying List of Lists

GKalman kalman_g at verizon.net
Thu Jun 26 23:49:15 CEST 2014


"""
Below I have two versions of a list of lists, named: RA
Version #1 is "hard-wired"
Version #2 is built-up from a sublist
Both versions print* identical* outputs

Yet if one or the other version is commented out, one get 
a* different* output in the modified list of lists

My  question is: why?

"""


from copy import deepcopy

#Version #1:
#==========
RA=[[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3]]
print "1a",RA,type(RA)


N=3
#Version #2:
#===========
RA=[]
Item=[1,2,3]
for i in range(N*N):
    RA.append(Item)
print "1b",RA,type(RA)

k=1
tv=1
cRA=deepcopy(RA)
LL=cRA[k]
print "LL before= ",LL
for c in range(N):
    if LL[c]==tv:
        LL[c]=0
print "LL after= ",LL
cRA[k]=LL
RA=cRA

#modified list of list:
#===============
print "2",RA




--
View this message in context: http://python.6.x6.nabble.com/Modifying-List-of-Lists-tp5062231.html
Sent from the Python - pythondotnet mailing list archive at Nabble.com.


More information about the PythonDotNet mailing list