[Python-ideas] Consider making enumerate a sequence if its argument is a sequence

Random832 random832 at fastmail.com
Wed Sep 30 21:25:54 CEST 2015


On Wed, Sep 30, 2015, at 13:19, Neil Girdhar wrote:
> I guess, I'm just asking for enumerate to go through the same change that
> range went through.  Why wasn't it a problem for range?

Range has always returned a sequence.

Anyway, why stop there? Why not have map return a sequence? Zip?
Anything that is a 1:1 mapping (or 1+1:1 in zip's case) could in
principle be changed to return a sequence when given one. Who decides
what does and doesn't benefit from random access?

Or sliceability. It wouldn't be hard, in principle, to write a
general-purpose function for slicing an iterator (i.e. returning an
iterator that yields the elements that slicing a list of the same length
would have given), particularly if it's limited to positive values.


More information about the Python-ideas mailing list