A curious bit of code...

Alain Ketterlin alain at dpt-info.u-strasbg.fr
Thu Feb 13 14:05:19 EST 2014


forman.simon at gmail.com writes:

> 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.
>
>   if key[:1] + key[-1:] == '<>': ...
>
> Some possibilities that occurred to me:
>
>   if key.startswith('<') and key.endswith('>'): ...
>
> and:
>
>   if (key[:1], key[-1:]) == ('<', '>'): ...

I would do: if key[0] == '<' and key[-1] == '>' ...

-- Alain.



More information about the Python-list mailing list