Python 'for' loop is memory inefficient
sturlamolden
sturlamolden at yahoo.no
Sun Aug 16 16:41:07 EDT 2009
On 16 Aug, 11:45, "bartc" <ba... at freeuk.com> wrote:
> A for-loop, for iterating over a simple sequence, should be one of the
> fastest things in the language.
Anyone experienced with interpreted high-level languages knows this is
not true. Not because iterating a sequence is expensive, but because
the interpreter is constantly executing the body of the loop. There is
a reason why Matlab and Python/NumPy programmers rely heavily on
vectorized array expressions for efficient numerics.
The only thing more evil than a for-loop is recursive function calls.
This does not mean Python is slow. It just means you have to program
differently.
More information about the Python-list
mailing list