>
> class AutoValueDict(dict):
>     def __makeitem__(self, key):
>         return self.setdefault(key, {})
>
>     def __getitem__(self, key):
>         return self.get(key, self.__makeitem__(key))
>
> I would like to have a dictionary which ensures dictionaries as values
> except when I'm assigning another:
>
> dict["abc"]["xyz"]["123"]["456"] = 123
>
> How can I do this without many "if" and "else"?
>

Oh no... of course like this:
    return self.setdefault(key, AutoValueDict())

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to