Python 'for' loop is memory inefficient
stefan_ml at behnel.de
Mon Aug 17 15:24:17 CEST 2009
John Machin wrote:
> On Aug 17, 8:35 am, sturlamolden <sturlamol... at yahoo.no> wrote:
>> A compiler could easily recognise a statement like
>> for i in range(n):
>> as a simple integer loop. In fact, Cython is able to do this.
> Extremely easy, once users relinquish the right to replace built-in
> "range" with their own concoctions ...
Cython allows you to do that. You just have to do it inside the module. If
Cython determines that "range" refers the global builtin name, it will
enable the loop optimisation. If you assign anything to that global name
inside your module (even the range function itself), this will disable the
More information about the Python-list