Quantcast

Modifying List of Lists

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Modifying List of Lists

GKalman
This post has NOT been accepted by the mailing list yet.
"""
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Modifying List of Lists

GKalman
This post has NOT been accepted by the mailing list yet.
OK testing
Loading...