On Wed, Aug 19, 2009 at 1:52 AM, Darth Kaboda<[email protected]> wrote:
> I'm questioning my reason for why the follwoing code doesn't behave as I
> thought it would upon first coding a project.
>
> m = 8
> n = 10
> cb = [[[0, None]] * (n + 1)] * (m + 1)
> cb[3][2][0] = 10
>
> This last statement causes the every first element in the list to update. Is
> this becuase this method of initializing a list is just a copy of the same
> list in memory?

Not literally a copy, but pointing to the same list. The correct term
is that each element of the list is a reference, or alias, to the same
list.

Kent
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to