On 8 April 2018 at 08:09, Tim Peters <[email protected]> wrote:
[Raymond wrote]:
>> The docs probably need another recipe to show this pattern:
>>
>>         def prepend(value, iterator):
>>             "prepend(1, [2, 3, 4]) -> 1 2 3 4"
>>             return chain([value], iterator)
>
> +1.  Whether `accumulate()` should grow a `start=` argument still
> seems a distinct (albeit related) issue to me, though.

I didn't have a strong opinion either way until Tim mentioned sum()
and then I went and checked the docs for both that and for accumulate.

First sentence of the sum() docs:

    Sums *start* and the items of an *iterable* from left to right and
returns the total.

First sentence of the accumulate docs:

    Make an iterator that returns accumulated sums, ...

So I now think that having "start" as a parameter to one but not the
other, counts as a genuine API discrepancy.

Providing start to accumulate would then mean the same thing as
providing it to sum(): it would change the basis point for the first
addition operation, but it wouldn't change the *number* of cumulative
sums produced.

By contrast, using the prepend() approach with accumulate() not only
changes the starting value, it also changes the number of cumulative
sums produced.

Cheers,
Nick.

-- 
Nick Coghlan   |   [email protected]   |   Brisbane, Australia
_______________________________________________
Python-ideas mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to