[Python-bugs-list] [Bug #119450] dictionary values returns pointers when the value is a list

noreply@sourceforge.net noreply@sourceforge.net
Thu, 26 Oct 2000 09:34:56 -0700


Bug #119450, was updated on 2000-Oct-26 08:20
Here is a current snapshot of the bug.

Project: Python
Category: None
Status: Closed
Resolution: Wont Fix
Bug Group: Not a Bug
Priority: 5
Summary: dictionary values returns pointers when the value is a list

Details: >>> dictio = {}
>>> dictio['a'] = ['a',[],""]
>>> temp = dictio['a']
>>> temp
['a', [], '']
>>> temp[-1] = 'c'
>>> temp
['a', [], 'c']
>>> dictio['a']
['a', [], 'c']

This is not documented. A simple way to fix it, is to copy the list when
the value is returned:


>>> dictio['a']
['a', [], 'd']
>>> temp = []+dictio['a']
>>> temp
['a', [], 'd']
>>> temp[-1] = 'e'
>>> dictio['a']
['a', [], 'd']


Follow-Ups:

Date: 2000-Oct-26 09:34
By: jhylton

Comment:
Python's reference semantics are documented.  This is not a bug.  If you want to copy a list when you extract it from a dictionary, then do it in your code.

-------------------------------------------------------

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=119450&group_id=5470