Mike Rovner wrote: > Paul Rubin wrote: > >> If the compiler can do some type inference, it can optimize out those >> multiple calls pretty straightforwardly. > > It can be tipped like that: > > di = dict(int) > di.setdefault(0) > di[key] += 1
Interesting, but why do you need to give the int type to the constructor? > dl = dict(list) > dl.setdefault([]) > dl.append("word") > dl.extend(mylist) I don't quite understand that. Which dict item are you extending? Don't you need something like dl[key].append("word") ? Anyway, using `setdefault' as the method name is quite confusing, although yours is IMHO a much better behavior given the name ;) So what about `setdefaultvalue'? Reinhold -- http://mail.python.org/mailman/listinfo/python-list