[issue29552] Issue in Dictionary fromkeys

2017-02-14 Thread Prudvi Mangadu

New submission from Prudvi Mangadu:

If we load the keys and values using fromkeys on dic.
Later the modification in the values is reflects for all keys in the DIC, 
please follow the below code.

###
PS C:\Python27> py
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> input = ['1','2']
>>> result = {}
>>> result = result.fromkeys(input,[])  >>>> Issue with this line
>>>
>>> result
{'1': [], '2': []}
>>>
>>> result['1'].append("item1")
>>>
>>> result
{'1': ['item1'], '2': ['item1']}   >>>>>>>>>>>>>>>>>> Here result['2'] also 
overwrites
>>>
>>> result['1'].append("item2")
>>> result
{'1': ['item1', 'item2'], '2': ['item1', 'item2']}   >>>>>>>>>>>>>>>>>> Here 
result['2'] also overwrites
>>>
>>>
###

--
components: Windows
messages: 287747
nosy: paul.moore, prudvibt81, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: Issue in Dictionary fromkeys
type: behavior
versions: Python 2.7

___
Python tracker 
<http://bugs.python.org/issue29552>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29552] Issue in Dictionary fromkeys

2017-02-14 Thread Prudvi Mangadu

Prudvi Mangadu added the comment:

Workaround is replace the below 2 lines with "result ={D_IP:[] for D_IP in 
input}"

==
result = {}
result = result.fromkeys(input,[])  >>>> Issue with this line
==

--

___
Python tracker 
<http://bugs.python.org/issue29552>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29552] Issue in Dictionary fromkeys

2017-02-14 Thread Prudvi Mangadu

Prudvi Mangadu added the comment:

Also observed that ID of the values are pointing same, its ok.
But if some one later modified that values which causes the un-usual output.

>>> id(result['1'])
38121184
>>> id(result['2'])
38121184

--

___
Python tracker 
<http://bugs.python.org/issue29552>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29552] Issue in Dictionary fromkeys

2017-02-14 Thread Prudvi Mangadu

Prudvi Mangadu added the comment:

Thanks Martin , I will close it.

--
stage:  -> resolved
status: open -> closed

___
Python tracker 
<http://bugs.python.org/issue29552>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com