Is this a bug in Python or something I do not understand.
semanticist at gmail.com
Thu Jan 1 19:20:51 CET 2009
On Thu, Jan 1, 2009 at 1:13 PM, <davidalvi at gmail.com> wrote:
> Consider these two lists comprehensions:
> L1=[[1 for j in range(3)] for i in range(3)]
> It seems a misbehaviour in Python, or there is something I do not
> understand in the syntax ????
It's not a Python bug. Does this help illuminate the difference?
>>> L1 = [object() for j in range(3)]
>>> L2 = [object()] * 3
>>> [id(o) for o in L1]
[164968, 164976, 164984]
>>> L1 is L1
>>> [id(o) for o in L2]
[164992, 164992, 164992]
>>> L2 is L2
More information about the Python-list