Georg Brandl <ge...@python.org> added the comment: I'll add a bit of explanation as well:
> I have to add this ugly loop : > > for key in keys: > d[key] = [] With a defaultdict, you don't -- you just use d[key], and if not already present, the entry will be initialized with an empty list. > I really think that : > 1) The doc should warn about it, since it is a very weird behaviour It is not weird in Python. Implicit copies are never made, partly because it's very hard to implement it correctly for every object. > 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) The interface of a fundamental type like "dict" will not be changed lightly. Usually, when a change is made, it is to add a feature that is often requested by lots of users -- I've never seen someone request this before. And as we've seen, it can easily be written either using a simple loop, or a defaultdict, depending on the exact use-case. ---------- nosy: +georg.brandl _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue6730> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com