Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!news.dfncis.de!not-for-mail From: Helmut Jarausch Newsgroups: comp.lang.python Subject: Re: How to make this faster Date: 5 Jul 2013 15:47:45 GMT Lines: 27 Message-ID: References: < b3o512Ftc39U3@mid.dfncis.de> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: news.dfncis.de LCzlh5fo50fjUcmg4YcURAx5ZMARgY5CN6dfQc8qNXdxBenOI85xe4szPv Cancel-Lock: sha1:1OqOIhORUX/dPsyIbI8PZqZBahM= User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) Xref: csiph.com comp.lang.python:49997 On Fri, 05 Jul 2013 16:18:41 +0100, Fábio Santos wrote: > On 5 Jul 2013 15:59, "Helmut Jarausch" wrote: >> >> On Fri, 05 Jul 2013 13:44:57 +0100, Fábio Santos wrote: >> May I suggest you avoid range and use enumerate(the_array) instead? It >> might be faster. >> >> How does this work? >> >> Given >> >> Grid= [[0 for j in range(9)] for i in range(9)] >> >> for (r,c,val) in ????(Grid) : >> >> Helmut > > for r, row_lst in enumerate(Grid): > for c, val in enumerate(row_lst): This is only slightly faster. I assume the creation of the temporary lists "row_list" is a bit expensive. Taking 5.4 seconds it's much slower than the current champion ( 0.79 seconds ) Thanks, Helmut.