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 64andy
Recipients 64andy
Date 2018-01-29.13:57:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1517234265.82.0.467229070634.issue32712@psf.upfronthosting.co.za>
In-reply-to
Content
If multiple lists/dictionaries are in the same memory address (usually caused by var1 = var2), then altering one will effect every variable in that address.
The ways I've found to achieve this are:
>>> my_list[2] = "Spam"
>>> my_list += "9"
>>> my_list.insert(4, "Hello")
>>> dictvar.update({"Three": "Four"})

This was achieved using Python 3.6.4 32-bit and 3.6.3 64-bit (CPython), and happened in both IDLE and python.exe

List Example code:
x = ['a','b','c']
y = x #Now y and x share a memory address, because CPython does that
print(f"Sanity test - x and y share the same address = {x is y}")

y[1] = '123'
y += ["Foo"]
y.insert(-1, "Eleven")

#x's Expected Value: ['a','b','c']
print(x) #Actual Value
History
Date User Action Args
2018-01-29 13:57:4564andysetrecipients: + 64andy
2018-01-29 13:57:4564andysetmessageid: <1517234265.82.0.467229070634.issue32712@psf.upfronthosting.co.za>
2018-01-29 13:57:4564andylinkissue32712 messages
2018-01-29 13:57:4564andycreate