defaultdict's bug or feature?
Red Forks
redforks at gmail.com
Thu May 21 08:07:50 EDT 2009
from collections import defaultdict
d = defaultdict(set)
assert isinstance(d['a'], set)
assert isinstance(d.get('b'), set)
d['a'] is ok, and a new set object is insert to d, but d.get('b') won't.
It's a bug, or just a feature?
I think dict.get() method is just a *safe* version of dict[key], maybe it
should be:
def get(self, key, default = None):
try:
return self[key]
except KeyError:
return default
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090521/4aeab122/attachment.html>
More information about the Python-list
mailing list