Don't overdo comprehensions and generators
We've seen how powerful list comprehensions and generator expressions can be. And they are, don't get me wrong, but the feeling that I have when I deal with them is that their complexity grows exponentially. The more you try to do within a single comprehension or a generator expression, the harder it becomes to read, understand, and therefore to maintain or change.
Open a Python console and type in import this
, let's read the Zen of Python again, in particular, there are a few lines that I think are very important to keep in mind:
>>> import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. # Simple is better than complex. # Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. # Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced...