[issue6730] dict.fromkeys() should not cross reference mutable value by default

Maxime Lemonnier report at bugs.python.org
Tue Aug 18 22:53:02 CEST 2009


Maxime Lemonnier <maxime.lemonnier at gmail.com> added the comment:

It does not suits my needs.

what if keys are passed as an argument?

I have to add this ugly loop :

for key in keys:
    d[key] = [] 
    

I really think that :
1) The doc should warn about it, since it is a very weird behaviour
2) There could at least be a third argument allowing the user to choose,
with a default value that maintains the current behaviour (for
compatibility, even though I think the default should be a deep copy)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6730>
_______________________________________


More information about the Python-bugs-list mailing list