Pre-PEP: Dictionary accumulator methods
Mike Rovner
mrovner at propel.com
Sun Mar 20 03:10:18 EST 2005
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
dl = dict(list)
dl.setdefault([])
dl.append("word")
dl.extend(mylist)
But the point is that if method not found in dict it delegated to
container type specified in constructor.
It solves dict specialization without bloating dict class and is generic.
Mike
More information about the Python-list
mailing list