This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author loewis
Recipients dschult, loewis, rhettinger
Date 2009-04-13.08:33:45
SpamBayes Score 2.1450866e-08
Marked as misclassified No
Message-id <49E2F8E8.7050205@v.loewis.de>
In-reply-to <7EF9FC9C-BC98-4E34-8DE2-BF9240B0452D@colgate.edu>
Content
> The missing key reports the default object, but doesn't set that key  
> or value object in the dict.

That's just not true. Re-read the line in the doc string where it
puts the default value into the dict, under the key being accessed.

> For example, to represent a graph structure, it is helpful to use a  
> dict-of-dicts.

No problem:

py> from collections import defaultdict
py> weights=defaultdict(dict)
py> weights['a']['b']=17
py> weights['a']['c']=5
py> weights['a']
{'c': 5, 'b': 17}

See? It remembered the default value, and the value for the 'a'
key got changed and can now be modified. The whole point of defaultdict
was to replace setdefault, so that setdefault can eventually be
eliminated, see

http://mail.python.org/pipermail/python-dev/2006-February/061169.html
http://mail.python.org/pipermail/python-dev/2006-February/061261.html

Apparently, the plan for removing setdefault is now forgotten. Perhaps
this would be a good time to revive it, with a proper deprecation
procedure. If it is to be removed, I'm -1 for "fixing" anything about
it.
History
Date User Action Args
2009-04-13 08:33:48loewissetrecipients: + loewis, rhettinger, dschult
2009-04-13 08:33:46loewislinkissue5730 messages
2009-04-13 08:33:46loewiscreate