On Mon, Dec 1, 2014 at 11:29 AM, Larry Martell <larry.mart...@gmail.com> wrote:
> I spoke too soon:
>
>>>> class defaultdictkey(defaultdict):
> ...  def __missing__(self, key):
> ...   self[key] = self.default_factory(key)
> ...
>>>> x = defaultdictkey(lambda k: k)
>>>> print x['aaa']
> None
>>>> print x['aaa']
> aaa
>>>> a = x['qqq']
>>>> print a
> None

You need to also return the value from __missing__.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to