Simple exercise

BartC bc at freeuk.com
Thu Mar 10 21:18:36 EST 2016


On 11/03/2016 02:03, Mark Lawrence wrote:
> On 11/03/2016 01:45, BartC wrote:
>> On 11/03/2016 01:21, Mark Lawrence wrote:
>>> On 11/03/2016 00:05, BartC wrote:
>>
>>>> def last(a):
>>>>      return a[-1]
>>>>
>>>> def init(a):                 # all except last element
>>>>      return a[0:len(a)-1]
>>>
>>> What is wrong with a[0:1] ?
>>
>> The returns the head of the list. I need everything except the last
>> element ('init' is from Haskell).
>
> I missed out one character, it should of course have been:-
>
> a[0:-1]

I tried that, but I must have got something wrong.

-- 
Bartc



More information about the Python-list mailing list