I was solving a problem on Hackerrank named "2d hourglass", i was unable to solve the problem, i searched their forums and found the solution, but I am unable to understand the solution
def hourglassSum(arr):
return(max([sum(arr[i][j:j+3] + [arr[i+1][j+1]] + arr[i+2][j:j+3]) for i in range(4) for j in range(4)]))
and also please explain me how the for loop at end works I am not accustomed to such implementation of for loop generaly I approach the for loops in this way:-
for i in range(4):
for j in range(4):
I only understand the working for loop when implemented in above mentioned way, I have stumbled upon many coded where for loops are in the end and I have never been able to understand them