aspineux <[EMAIL PROTECTED]> writes: > Yes, I missed 'get' and 'setdefault' are functions :-) > Then why not some new semantic > > d.get('a', f()) --> d['a', f()] > d.setdefault('a', f()) --> d['a'=f()] > > Is is a good idea enough to change the python semantic ? > Or simply is it a good idea ?
Changing python semantics for something like this is nuts. Allowing passing a callable (sort of like re.sub allows) makes a certain amount of sense: d.get('a', default=f) You can also write (python 2.5, untested): d['a'] if 'a' in d else f() -- http://mail.python.org/mailman/listinfo/python-list