A curious bit of code...
Neil Cerutti
neilc at norwich.edu
Thu Feb 13 14:17:29 EST 2014
More information about the Python-list mailing list
Thu Feb 13 14:17:29 EST 2014
- Previous message (by thread): A curious bit of code...
- Next message (by thread): A curious bit of code...
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 2014-02-13, forman.simon at gmail.com <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. > > if key[:1] + key[-1:] == '<>': ... > > Some possibilities that occurred to me: > > if key.startswith('<') and key.endswith('>'): ... > > and: > > if (key[:1], key[-1:]) == ('<', '>'): ... > > > I haven't run these through a profiler yet, but it seems like > the original might be the fastest after all? I think the following would occur to someone first: if key[0] == '<' and key[-1] == '>': ... It is wrong to avoid the obvious. Needlessly ornate or clever code will only irritate the person who has to read it later; most likely yourself. -- Neil Cerutti
- Previous message (by thread): A curious bit of code...
- Next message (by thread): A curious bit of code...
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list