Why Python does *SLICING* the way it does??

Paul Rubin http
Thu Apr 21 04:04:21 EDT 2005


Antoon Pardon <apardon at forel.vub.ac.be> writes:
> I sometimes think python should have been more explicite here,
> using a marker for the start-index and end-index, may '^' and
> '$'. So if you wanted the last element you had to write:
> 
>   lst[$]
> 
> And for the next to last element:
> 
>   lst[$ - 1]

I like this.  I don't know how many times I've gotten screwed by
wanting the n'th element from the last for variable n, and saying
"lst[n]" then realizing I have a bug when n=0.  lst[$-n] works perfectly.



More information about the Python-list mailing list