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: a.append appends reference , causing unexpected behaviour
Type: behavior Stage:
Components: Interpreter Core Versions: Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, hamish.farrant
Priority: normal Keywords:

Created on 2010-03-06 22:26 by hamish.farrant, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg100548 - (view) Author: hamish farrant (hamish.farrant) Date: 2010-03-06 22:26
Causes modification of an list object to change the values of the object already inside the list.

Example code :

import random
a  =[]
b = [1 , 2 , 3 , 4]
for i in range (15):
    random.shuffle(b)
    a.append(b)
for j in a:
    print j

Expected Behaviour : the list referenced by b , should be appended to a , creating a list of random permutations of b.
msg100549 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-03-06 22:31
Sorry, this is the expected behavior. Copy the list if you want a different one.
History
Date User Action Args
2022-04-11 14:56:58adminsetgithub: 52328
2010-03-06 22:31:56benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg100549

resolution: not a bug
2010-03-06 22:26:14hamish.farrantcreate