On Apr 6, 11:16 pm, Helmut Jarausch <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I must be blind but I don't see what's going wrong
> with
The reason is:
> G=[[]]*2
is doing a "shallow copy" of the blank list. The corrected code is
either:
G = [[] for _ in xrange(2)]
or
G = [[], []]
btw, this is a
On Apr 6, 5:16 pm, Helmut Jarausch <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I must be blind but I don't see what's going wrong
> with
>
> G=[[]]*2
>
> G[0].append('A')
> G[1].append('B')
> print G[0]
>
> gives
>
> ['A', 'B']
>
> as well as
> print G[1]
>
> I was expecting
> ['A']
> and
> ['B']
> respec
Hi,
I must be blind but I don't see what's going wrong
with
G=[[]]*2
G[0].append('A')
G[1].append('B')
print G[0]
gives
['A', 'B']
as well as
print G[1]
I was expecting
['A']
and
['B']
respectively.
Many thanks for enlightening me,
Helmut.
--
Helmut Jarausch
Lehrstuhl fuer Numerische Mat