On Jul 19, 6:29 am, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:

>
> Myobject will be instanciated each time, yes.
>
> > and so if the initialization is expensive you
> > will probably see surprises.
>
> No "surprise" here, but it can indeed be suboptimal if instanciating
> myobject is costly.

What about this way ?

my_obj = my_dict.get(key) or my_dict.setdefault(key,myobject())

Ciao
G.

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

Reply via email to