[Python-Dev] Adding start to enumerate()
Georg Brandl
g.brandl at gmx.net
Tue May 13 21:22:57 CEST 2008
Guido van Rossum schrieb:
> On Tue, May 13, 2008 at 11:59 AM, Facundo Batista
> <facundobatista at gmail.com> wrote:
>> 2008/5/13, Steven D'Aprano <steve at pearwood.info>:
>>
>>
>> > Perhaps what we need is a more flexible enumerate function?
>> > enumerate(iterable, start_at_index=0, count_from=0)
>>
>> +1 to provide both options: they're not intrusive (as I can keep using
>> enumerate without those), and having both helps in the understanding
>> of the function.
>>
>> I mean, if I find an option that is "start", I can confuse if it will
>> start counting or giving me the elements of the iterable... if I found
>> both parameters, it will be easier to understand.
>
> Actually, having both dramatically increases the potential for
> confusion. Once you have the starting index option, you're always
> going to be worried about whether the first index generated defaults
> to zero or to the starting index, since depending on your use case one
> or the other is vastly more useful...
>
> We already have itertools.islice() which can handle both of these
> easily (slice the input or slice the output).
>
> -1 on providing a start index.
> +1 on providing a start value for the count, making it a
> positional-with-optional-keyword-name ('start') parameter.
This is what's now implemented in SVN. Thanks for the discussion!
cheers,
Georg
More information about the Python-Dev
mailing list