R. David Murray <rdmur...@bitdance.com> added the comment: I wrote up a response before Mark closed the issue, so despite his excellent no discussion suggestion I'm going to post it for the edification of anyone reading the issue later rather than waste the work :)
Nathan: this is *long* established behavior of python. It is baked in to the language. Even if we thought it was a good idea to change it, that cannot be done for backward compatibility reasons. As for why it works the way it does, consider the following (potentially useful!) cases: > [1, 2] * 5 [1, 2, 1, 2, 1, 2, 1, 2, 1, 2] > [(1, 2)] * 5 [(1, 20), (1, 20), (1, 20), (1, 20), (1, 20)] What Python is doing is filling the created list with *copies of the pointers to the listed values*, which is much more sensible than creating, say, multiple copies in memory of the integers 1 and 2. That is, you are observing a specific, non-intuitive and rarely useful result of a general rule that *is* useful and intuitive. Also note that *even if* we wanted to try to make exceptions for "mutable" verses "non-mutable" elements when doing this replication, we can't, because there's a difference between 'copy' and 'deepcopy' in Python, and Python refuses to guess. So, if you want copies of a list, *you* have to make the correct kind of copies for your application. Python just copies the pointers like it does for every other type of object multiplied into a list. By the way, when a core dev closes an issue, the convention is that you can present an argument for it being reopened, but you don't reopen it yourself. (No way for you to know that that is our convention, which is why I'm telling you :) But as should be clear by now, this is a closed issue and further discussion here would be counter-productive for all of us. ---------- nosy: +r.david.murray _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue33636> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com