Programming Recommendations
https://www.python.org/dev/peps/pep-0008/#programming-recommendations
Use is not operator rather than not … is. While both expressions are functionally identical, the former is more readable and preferred.
Always use a def statement instead of an assignment statement that binds a lambda expression directly to an identifier.
Derive exceptions from Exception rather than BaseException. Direct inheritance from BaseException is reserved for exceptions where catching them is almost always the wrong thing to do.
Design exception hierarchies based on the distinctions that code catching the exceptions is likely to need, rather than the locations where the exceptions are raised. Aim to answer the question “What went wrong?” programmatically, rather than only stating that “A problem occurred” (see PEP 3151 for an example of this lesson being learned for the builtin exception hierarchy)
For sequences, (strings, lists, tuples), use the fact that empty sequences are false.
Yes: if not seq:
if seq:
No: if len(seq):
if not len(seq):