A curious bit of code...

Mark Lawrence breamoreboy at yahoo.co.uk
Thu Feb 13 14:32:17 EST 2014


On 13/02/2014 19:25, Neil Cerutti wrote:
> On 2014-02-13, Ethan Furman <ethan at stoneleaf.us> wrote:
>> On 02/13/2014 11:09 AM, Mark Lawrence wrote:
>>> All I can say is that if you're worried about the speed of a
>>> single line of code like the above then you've got problems.
>>> Having said that, I suspect that using an index to extract a
>>> single character has to be faster than using a slice, but I
>>> haven't run these through a profiler yet :)
>>
>> The problem with using indices in the code sample is that if
>> the string is 0 or 1 characters long you'll get an exception
>> instead of a False.
>
> There will be an exception only if it is zero-length. But good
> point! That's a pretty sneaky way to avoid checking for a
> zero-length string. Is it a popular idiom?
>

I hope not.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com





More information about the Python-list mailing list