Martin v. Löwis <mar...@v.loewis.de> added the comment:

> By the way, defaultdict is NOT like setdefault--it is like get().
> Missing entries do no get set.

Why do you say that?

__missing__(...)
    __missing__(key) # Called by __getitem__ for missing key; pseudo-code:
    if self.default_factory is None: raise KeyError((key,))
    self[key] = value = self.default_factory()
    return value

In all cases of setdefault that I know of, replacing this with
a defaultdict would be appropriate. The only case where it wouldn't
work is if the default value depends on the key.

> What do you think?

If no speedup can be demonstrated, we should not change it.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue5730>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to