Is this a bug in Python or something I do not understand.
Chris Rebert
clp at rebertia.com
Thu Jan 1 16:00:25 EST 2009
On Thu, Jan 1, 2009 at 10:13 AM, <davidalvi at gmail.com> wrote:
> Consider these two lists comprehensions:
>
> L1=[[1 for j in range(3)] for i in range(3)]
> L2=[[1]*3]*3
<snip>
> So far, everything is OK, but let us now modify the lists' contents in
> the following way:
<snip>
> It seems a misbehaviour in Python, or there is something I do not
> understand in the syntax ????
The latter, and it's a FAQ. Please read
http://www.python.org/doc/faq/programming/#how-do-i-create-a-multidimensional-list
(it's question 4.6).
Cheers,
Chris
--
Follow the path of the Iguana...
http://rebertia.com
More information about the Python-list
mailing list