How to make this faster
jarausch at igpm.rwth-aachen.de
Fri Jul 5 17:47:45 CEST 2013
On Fri, 05 Jul 2013 16:18:41 +0100, Fábio Santos wrote:
> On 5 Jul 2013 15:59, "Helmut Jarausch" <jarausch at igpm.rwth-aachen.de> 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?
>> Grid= [[0 for j in range(9)] for i in range(9)]
>> for (r,c,val) in ????(Grid) :
> 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 )
More information about the Python-list