This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author georg.brandl
Recipients beco, georg.brandl
Date 2007-11-09.13:19:46
SpamBayes Score 0.07302072
Marked as misclassified No
Message-id <1194614387.05.0.822149561187.issue1408@psf.upfronthosting.co.za>
In-reply-to
Content
I'm sorry, this is no bug. List multiplication works by referencing,
there is no way to implement it differently in a straightforward way.

Note that in
>>> [a[:]] + [a[:]]
the expression "a[:]" is evaluated twice, yielding two independent
copies of a. In contrast,
>>> [a[:]] * 2
evaluates "a[:]" only once, before the list multiplication is done.
Because of the same reason,
>>> [deepcopy(a)] * 2
doesn't work as you want.

One way to do what you have in mind is
>>> [a[:] for i in range(2)]
which evaluates the "a[:]" once for each iteration of the list
comprehension loop.
History
Date User Action Args
2007-11-09 13:19:47georg.brandlsetspambayes_score: 0.0730207 -> 0.07302072
recipients: + georg.brandl, beco
2007-11-09 13:19:47georg.brandlsetspambayes_score: 0.0730207 -> 0.0730207
messageid: <1194614387.05.0.822149561187.issue1408@psf.upfronthosting.co.za>
2007-11-09 13:19:47georg.brandllinkissue1408 messages
2007-11-09 13:19:46georg.brandlcreate