Why Python does *SLICING* the way it does??
Reinhold Birkenfeld
reinhold-birkenfeld-nospam at wolke7.net
Thu Apr 21 06:49:38 EDT 2005
Antoon Pardon wrote:
> Op 2005-04-21, Reinhold Birkenfeld schreef <reinhold-birkenfeld-nospam at wolke7.net>:
>> Antoon Pardon wrote:
>>
>>> 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]
>>>
>>>
>>> This would make accessing list elements counted from the rear
>>> almost just as easy as it is now but wouldn't interfere with
>>> the ask forgiveness programming style.
>>
>> How would you pass this argument to __getitem__?
>
> Well assuming lst.last, was the last index of lst, __getitem__
> would get lst.last and lst.last - 1 passed.
Then it would be an alias for len(lst)-1 ?
>> What would be allowed, only '$-x' or also '$+x' or what else?
>
> Any expression where an int is allowed.
Okay.
>> What type would '$' be?
>
> It would be an int.
Where would it be allowed? Only in subscriptions?
Reinhold
More information about the Python-list
mailing list