On Jan 14, 2008 1:39 PM, aspineux <[EMAIL PROTECTED]> wrote: > > This append in both case > > dict(a=1).get('a', f()) > dict(a=1).setdefault('a', f()) > > This should be nice if f() was called only if required.
Shortcomings of those methods is probably why collections.defaultdict is so popular. >>> def f(): ... return 7 ... >>> d = defaultdict(f, a=1) >>> d['a'] 1 >>> d['b'] 7 get and setdefault aren't needed when using a default dict, and the default factory is called only when needed. -- Neil Cerutti <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list