Message 85854 - Python tracker

Message85854

Author loewis
Recipients dschult, loewis, rhettinger
Date 2009-04-11.12:15:14
SpamBayes Score 9.109828e-07
Marked as misclassified No
Message-id <49DF1236.5020304@v.loewis.de>
In-reply-to <666A36BE-5DEB-4A8C-B524-FC6A4D89E071@colgate.edu>
Content
> 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.
History
Date User Action Args
2009-04-11 12:15:18loewissetrecipients: + loewis, rhettinger, dschult
2009-04-11 12:15:15loewislinkissue5730 messages
2009-04-11 12:15:14loewiscreate