Efficiency of list comprehensions
blog.cdleary.com
blog.cdleary.com
2. This is very interpreter-dependent. Any JIT worth its salt (like, say, PyPy) would probably decide to inline the append code if we're in this loop long enough for it to matter.
I do agree with the author that using a comprehension for the side-effect is smelly.
As others suggest I'm probably all wet about savings vs. a simple loop because of instantiation etc. And I don't think I'd ever use expressions like these merely for their side effects. I do expect that at a certain problem size the cumulative costs of building the list in a list comp will swamp the generator instantiation costs of gen exps consumed by iterator-friendly functions.
The beauty of Python is that the one, obvious way to do something is usually the right way. When you try to force something like this, you either run into silly bugs like "any" short-circuiting, or you waste your limited brainpower trying to avoid them. You're usually better off looking for algorithmic or architectural optimizations for speed, or refactoring for readability.
Once you are at the point of considering execution time to be a side effect, the purity of any non-trivial expression vanishes.