A curious bit of code...

Tim Chase python.list at tim.thechases.com
Thu Feb 13 21:39:27 CET 2014


On 2014-02-13 10:37, forman.simon at gmail.com wrote:
> I ran across this and I thought there must be a better way of doing
> it, but then after further consideration I wasn't so sure.
> 
> Some possibilities that occurred to me:
> 
>   if key.startswith('<') and key.endswith('>'): ...

This is my favorite because it doesn't break on the empty string like
some of your alternatives.  Your k[0] and k[-1] assume there's at
least one character in the string, otherwise an IndexError is raised.

-tkc







More information about the Python-list mailing list