Pre-PEP: Dictionary accumulator methods

Ron radam2 at tampabay.rr.com
Sun Mar 20 06:43:28 CET 2005


On Sat, 19 Mar 2005 01:24:57 GMT, "Raymond Hettinger"
<vze4rx4y at verizon.net> wrote:

>        def count(self, value, qty=1):
>            try:
>                self[key] += qty
>            except KeyError:
>                self[key] = qty
>
>        def appendlist(self, key, *values):
>            try:
>                self[key].extend(values)
>            except KeyError:
>                self[key] = list(values)


Why is it better than this? 

dict[key]+=n
dict[key]+=list  

Ron




More information about the Python-list mailing list