A curious bit of code...

Emile van Sebille emile at fenx.com
Thu Feb 13 16:23:20 EST 2014


On 2/13/2014 1:10 PM, Chris Angelico wrote:
> On Fri, Feb 14, 2014 at 8:06 AM, Peter Otten <__peter__ at web.de> wrote:
>> For the record:
>>
>>>>> s = "x"
>>>>> s[::len(s)-1]
>> Traceback (most recent call last):
>>    File "<stdin>", line 1, in <module>
>> ValueError: slice step cannot be zero
>
> And that, my friends, is a classic example of a Python exception that
> ought to be a subclass of UnhingedProgrammerError.
>

And certainly s[::len(s)-1 or 1] isn't any better.  :)

Emile






More information about the Python-list mailing list