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.

classification
Title: tuple-to-list conversion
Type: Stage:
Components: Versions: Python 3.1, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: pyry.saila, rhettinger
Priority: normal Keywords:

Created on 2010-09-03 02:57 by pyry.saila, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg115413 - (view) Author: Pyry Säilä (pyry.saila) Date: 2010-09-03 02:57
As I am new to Python and programming as a whole, I do not have extensive knowledge of how to correctly report a bug. And as such I must apologize for the inconvenience.

My lack of knowledge makes this only an assumption, but...

---

>>>l
[(1, 4, 7), (2, 5, 8), (3, 6, 9)]
>>>q = r = s = []
>>>for i in range(len(l)):
...    for x in l[i]:
...        q.append(x)
...    s = q
...    q = []
...    print s,    # print used to increase clarity
...    r.append(s)
...    print r    # and the next is printed out as:
...
[1, 4, 7] [1, 4, 7, [...]]
[2, 5, 8] [1, 4, 7, [...], [2, 5, 8]]
[3, 6, 9] [1, 4, 7, [...], [2, 5, 8], [3, 6, 9]]
>>>r
[1, 4, 7, [...], [2, 5, 8], [3, 6, 9]]
>>>r[3]    # for extra
[1, 4, 7, [...], [2, 5, 8], [3, 6, 9]]

---

Supposed outcome for r being [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
msg115418 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-09-03 04:39
Sorry, this isn't a bug.  I think you've rediscovered a property of mutable objects.  See http://docs.python.org/tutorial/controlflow.html#default-argument-values for an example.
msg115422 - (view) Author: Pyry Säilä (pyry.saila) Date: 2010-09-03 07:15
Ah, I see. What a stupid error. My apologies.
History
Date User Action Args
2022-04-11 14:57:06adminsetgithub: 53958
2010-09-03 07:15:12pyry.sailasetmessages: + msg115422
2010-09-03 04:39:15rhettingersetstatus: open -> closed

nosy: + rhettinger
messages: + msg115418

resolution: not a bug
2010-09-03 02:58:21pyry.sailasetcomponents: - None
2010-09-03 02:57:01pyry.sailacreate