Cleaning up conditionals

Erik python at
Fri Dec 30 19:43:28 EST 2016

On 31/12/16 00:26, Deborah Swanson wrote:
> As Mr. Bieber points out, what I had above greatly benefits from the use
> of conjunctions. It now reads:
> if not len(l1[st]) and len(l2[st]):

IMHO, "if not len(l)" is a _terrible_ way of spelling "if len(l) == 0" 
(mentally, I have to read that as "if length of 'l' is not not equal to 
0" - and a double negative won't never cause problems ( ;) )).

Also, in that particular expression, having to know off the top of their 
head the precedence of 'not' and 'and' will cause at least some 
percentage of your maintenance audience in the future to get it wrong.

What's wrong with:

if len(l1[st]) == 0 and len(l2[st]) != 0:


There is _no way_ someone could read that and get the wrong idea.


More information about the Python-list mailing list