Slicing history?
Jon Clements
joncle at googlemail.com
Sun Nov 15 14:01:49 EST 2009
On Nov 15, 6:50 pm, a... at pythoncraft.com (Aahz) wrote:
> Anyone remember or know why Python slices function like half-open
> intervals? I find it incredibly convenient myself, but an acquaintance
> familiar with other programming languages thinks it's bizarre and I'm
> wondering how it happened.
> --
> Aahz (a... at pythoncraft.com) <*> http://www.pythoncraft.com/
>
> [on old computer technologies and programmers] "Fancy tail fins on a
> brand new '59 Cadillac didn't mean throwing out a whole generation of
> mechanics who started with model As." --Andrew Dalke
Good ol' zero based indexing. It makes a lot more sense that range(len
(my_list)) returns 'n' values which are valid indicies, otherwise
they'd be a lot of IndexError's being raised.
Besides, when you really want the full range (a corner case), it's a
lot easier to do a +1, than to force people to write -1 for the vast
majority of cases.
Jon.
More information about the Python-list
mailing list