[docs] [issue23406] interning and list comprehension leads to unexpected behavior

Georg Brandl report at bugs.python.org
Sat Feb 7 14:10:34 CET 2015


Georg Brandl added the comment:

There is no interning going on.  Multiplying lists just copies references.

This is not so surprising if you consider that the case may be simple for nested lists, but what about ``[a] * 3`` with some arbitrary object "a"?  Copying (or even deep copying) that object is usually not wanted, and impossible in general.

This is also documented here (see especially note 2 below the table):
https://docs.python.org/2/library/stdtypes.html#sequence-types-str-unicode-list-tuple-bytearray-buffer-xrange

You're right though that this might be good to mention in the tutorial, as it comes up every now and then.  I'll leave the issue open to discuss that.

----------
nosy: +georg.brandl

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23406>
_______________________________________


More information about the docs mailing list