On Sat, 19 Mar 2005 15:17:59 GMT, "Raymond Hettinger" <[EMAIL PROTECTED]> wrote:
> [Dan Sommers] >> Curious that in this lengthy discussion, a method name of >> "accumulate" never came up. I'm not sure how to separate the two >> cases (accumulating scalars vs. accumulating a list), though. > Separating the two cases is essential. Also, the wording should > contain strong cues that remind you of addition and of building a > list. Agreed, with a slight hedge towards accumulation or tabulation rather than addition. I don't think "summation" gets us anywhere, either. Are the use cases for qty != 1 for weighted averages (that's the only one I can think of off the top of my head)? Is something like this: def accumulate( self, key, *values ): if values == ( ): values = 1 try: self[ key ] += values except KeyError: if type( key ) == int: self[ key ] = 1 else self[ key ] = *values possible? It's more "klunky" than I thought it would be before I started typing it out. Then we'd have these two use cases: histogram = { } for word in text.split( ): histogram.accumulate( word ) and org_chart = { } for employee in employees: org_chart.accumulate( employee.manager, employee.name ) Regards, Dan -- Dan Sommers <http://www.tombstonezero.net/dan/> Îâ à Îâ à c = 1 -- http://mail.python.org/mailman/listinfo/python-list