> > So here's a strawman implementation: > > > > def sum(seq, start=0): > > if isinstance(start, basestring): > > raise TypeError, "can't sum strings; use ''.join(seq) instead" > > return reduce(operator.add, seq, start) > > > > Alex, go ahead and implement this! > > Coming right up! For the C implementation, consider bypassing operator.add and calling the nb_add slot directly. It's faster and fulfills the intention to avoid the alternative call to sq_concat. Also, think about whether you want to match to two argument styles for min() and max(): >>> max(1,2,3) 3 >>> max([1,2,3]) 3 When the patch is ready, feel free to assign it to me for the code review. Raymond Hettinger P.S. Your new builtin works great with itertools. def dotproduct(vec1, vec2): return sum(itertools.imap(operator.mul, vec1, vec2))
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4