help for embedded list

Greg Ewing greg.ewing at compaq.com
Thu Oct 28 03:36:17 EDT 1999


kirank at bom3.vsnl.net.in wrote:
> 
> why does this happen ? I want only the first element in row 0,column 0
> to change.How can i achieve this ?

You don't show how you created the array, but you've
obviously created an outer list containing several
references to the same inner list. You need to create
a new inner list for each row of the array, e.g.

   grid = []
   for i in range(8):
      grid.append(range(8))

Keep in mind that in Python an assignment statement
only assigns a *reference* to whatever object the
right hand side denotes -- it never copies an object
or creates a new object.

Greg




More information about the Python-list mailing list