[Edu-sig] how to make clear: understand references
Kirby Urner
urnerk@qwest.net
Sat, 21 Sep 2002 08:51:31 -0700
At 04:24 PM 9/20/2002 -0400, Douglas S. Blank wrote:
>I did give two examples of multi-dimensional arrays, but the issue,
>I believe, is with the operators, not the arrays. I had suggested:
>
> >>> a = [[0] * 5].copy() * 3
This wouldn't be conceptually right anyway, as you're getting the
copy _before_ you replicate the thing three times -- then you
replicate the very same copy. But it's at the replication stage
that you want the copies.
> >>> a = [deepcopy([0] * 6)] * 3 # or
Same problem -- first you deepcopy, then you use * to replicate.
What you need is:
>>> a = a + deepcopy(a) + deepcopy(a)
Kirby