append to a sublist - please help

Lie Lie.1296 at gmail.com
Sun Apr 6 13:36:51 EDT 2008


On Apr 6, 11:16 pm, Helmut Jarausch <jarau... at skynet.be> 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 very frequently asked question



More information about the Python-list mailing list