I tried to construct in python a functon which includes a for loop to iterate a function that computes a double integral. This is the code:
def bestset():
sumsqu = [sqres(grid[i]) for i in range(len(grid))]
index_min = min(xrange(len(sumsqu)), key=sumsqu.__getitem__)
return index_min
sqres is a function that contains the computation of such double integral while grid is a list of lenght 5^5=3125. The problem of slowness derives from such for loop inside the list. I tried to reduce the lenght of grid to 3^5 elements, but I takes around 20 minutes to perform the loop. Obviously it takes age to perform the for loop with 3125 elements. Is there a way to improve the speed of it in python?