2018-04-08 8:19 GMT+03:00 Nick Coghlan <ncogh...@gmail.com>: > A name like "first_result" would also make it clearer to readers that > passing that parameter has an impact on the length of the output > series (since you're injecting an extra result), and also that the > production of the first result skips calling func completely (as can > be seen in Tim's str coercion example). > > So where I'd be -1 on: > > >>> list(accumulate(1, 2, 3)) > [1, 3, 6] > >>> list(accumulate(1, 2, 3, start=0)) > [0, 1, 3, 6] > >>> list(accumulate(1, 2, 3, start=1)) > [1, 2, 4, 7] > > I'd be +1 on: > > >>> list(accumulate(1, 2, 3)) > [1, 3, 6] > >>> list(accumulate(1, 2, 3, first_result=0)) > [0, 1, 3, 6] > >>> list(accumulate(1, 2, 3, first_result=1)) > [1, 2, 4, 7] > > It is a fair point! But the usual way to understand how to use an additional argument, is to try it or to look examples in the documentation.
Concerning the topic of relationship between `sum` and `accumulate` I have another point of view. If `start` means something to the `sum`, there are no grounds for believing that it should mean the same for `accumulate`, these functions are not really comparable and fundamentally different. The closest `sum`s friend is `functools.reduce` which uses `initial` instead of `start`. ( the documentation uses `initializer` and the docstring uses `initial`, as for me I prefer the `initial`) and so there is already a discrepancy. Having said this I think that it is no matter how it will be named `start` or `initial` or `first_result` or `first`, which is more suitable. I would prefer `initial` to be the same as in `itertoolz` package. Regarding the second point, should it yield one more element if provided - I think everyone here agrees that yes. With kind regards, -gdg
_______________________________________________ Python-ideas mailing list Pythonemail@example.com https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/