array of arrays question

Paul Rubin http
Tue Aug 30 11:12:22 CEST 2005

"Meo" <eric.paquet at> writes:
> Somebody understand what's going on here?

Yes, []*3 gives you three references to the same empty list, not three
separate empty lists.  You need something like

   [[] for i in xrange(3)]

to get separate lists.

Another example:

    a = [1,2,3]
    b = a
    a[0] = 5
    print b   # prints [5,2,3]

Do you understand now?

More information about the Python-list mailing list