a possibly foolish question about slices

Eddie Corns eddie at holyrood.ed.ac.uk
Fri Jun 14 21:44:44 CEST 2002


Andrew Koenig <ark at research.att.com> writes:

>Eddie> Hmm, I was actually trying to suggest (non-seriously) fixing
>Eddie> zero based indexing! but I realise now that wasn't clear.

>It's hard to imagine how it would be possible to change to 1-based
>indexing without breaking lots of code.

No pain, no gain :)

>For that matter, I had the thought that it might be possible simply
>to define x[n:0] as meaning x[n:len(x)] if n<0, but I imagine that
>even that would break too much code.

No, I was experimenting along those lines but couldn't see a way to do it
without breaking compatability.

Of course that solution from that clever David Eppstein chap works for the
case you asked about.  The case I always seem to want to do is chop n
characters of the end of a string where n sometimes turns out to be 0.  Still
the '[:n or maxint]' solution is good enough.

Eddie



More information about the Python-list mailing list