Author martin.panter
Recipients martin.panter, paul.moore, prudvibt81, steve.dower, tim.golden, zach.ware
Date 2017-02-14.11:55:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
This is similar to the problem of building a list by repeating one item: <>.

With dict.fromkeys(), the resulting dictionary maps each specified key object to the one and only value object (empty list) you passed to fromkeys(). If you look up one of the keys, it returns the list object. If you modify that object, all references to that object will see the update.

The difference with the dictionary comprehension workaround is that the interpreter executes the expressions “D_IP” and “[]” once for each iteration of “input”, resulting in a new empty list instance each iteration. But when you call fromkeys(), you pass a single object. The fromkeys() method just copies references; it does not create objects itself.

If the id() function returns the same identity, it means you have two references to the same underlying object instance. This is the same as checking “result['1'] is result['2']”.
Date User Action Args
2017-02-14 11:55:28martin.pantersetrecipients: + martin.panter, paul.moore, tim.golden, zach.ware, steve.dower, prudvibt81
2017-02-14 11:55:28martin.pantersetmessageid: <>
2017-02-14 11:55:28martin.panterlinkissue29552 messages
2017-02-14 11:55:27martin.pantercreate