A curious bit of code...

Roy Smith roy at panix.com
Thu Feb 13 14:28:41 EST 2014


In article <mailman.6859.1392319225.18130.python-list at python.org>,
 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.

My re.match() solution handles those edge cases just fine.



More information about the Python-list mailing list